Why can't type "S4" be forced into a vector of type "integer"?

Can someone tell me why I get this error
  Error in as.integer(tm) : cannot coerce type 'S4' to vector of type 'integer:?
I searched the internet but could not solve my problem.

      library(Matrix)
     long <- file("C:\\New folder (5)\\inra.bin", "rb")
     A=readBin(long, integer(), size=2,n=67420*1, signed=F)
    ta<-t(A)
  lot <- file("C:\\New folder (5)\\lat.img", "rb")
    B=readBin(lot, integer(), size=2,n=67420*1, signed=F)
     tb<-t(B)
       wind <- file("C:\\Wind_WFD_200201.bin", "rb")
       C=readBin(wind, double(), size=4,n=67420*248, signed=TRUE)
        D<-matrix(C,nrow=248,ncol=67420)
         for(d in 1:31)
       {
        M <- Matrix(-9999, 360, 720)
         tm<-t(M)
       for(i in 1:67420)
       {
    tm[ta[i],tb[i]]= 10 * ((D[(d-1)*8+1,i] + D[(d-1)*8+2,i] +D[(d-1)*8+3,i] +D[(d- 1)*8+4,i] +D[(d-1)*8+5,i] +D[(d-1)*8+6,i] +D[(d-1)*8+7,i] +D[(d-1)*8+8,i] ) / 8)

 }###gooooooood
 to.write <- sprintf("C:\\Yar_%0d.bin", d)
 writeBin(as.integer(tm), size=2,to.write)

}

+3
source share
1 answer

Take a look at How to split and write to the file for the S4 object in the R . In your case, the MatrixS4 object seems to return. Try the following:

foo <- Matrix(10,10,10)
slotnames(foo) 

, tm.
Matrix ? base::matrix, . : Matrix,, , as.integer . , as(x,matrix).

+2

All Articles