Can anyone tell me why I am getting this error:
Error in as.integer(tm) : cannot coerce type 'S4' to vector of type 'integer?
I have been searching the internet but couldn't solve my problem.
long <- file("C:\\New folder (5)\\inra.bin", "rb")
A=readBin(long, integer(), size=2,n=67420*1, signed=F)
lot <- file("C:\\New folder (5)\\lat.img", "rb")
B=readBin(lot, integer(), size=2,n=67420*1, signed=F)
wind <- file("C:\\Wind_WFD_200201.bin", "rb")
C=readBin(wind, double(), size=4,n=67420*248, signed=TRUE)
for(d in 1:31)
M <- Matrix(-9999, 360, 720)
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)
to.write <- sprintf("C:\\Yar_%0d.bin", d)
Take a look at How to split and write to a file for S4 object in R . In your case, it appears that
Matrix returns an S4 object. Try this:
foo <- Matrix(10,10,10) slotnames(foo)
That may give a suggestion as to what you want to extract from your
But why are you using
Matrix in the first place? If you just use
base::matrix this problem should disappear.
Edit: peeking at the documentation for package
Matrix, it's clear that
as.integer is not supported. You probably would have to use