[R] write to M, using row and columns taken from A and B, with values from C

Amen amen.alyaari at Bordeaux.inra.fr
Thu Apr 26 10:25:58 CEST 2012


 I want to write to M, using row and columns taken from A and B, with values
from C. C is a lot longer than A  and B, so only the first 67420 elements of
C are used in my loop.So how can I improve it to take then the next 67420
and write it to new file and so on till the 248th 67420. Many thanks 


library(Matrix)
 M <- Matrix(-9999, 360, 720)   ## creat matrix with 720 columns and 360 ro
ws with valus of -9999
 long <- file("C:\\New folder (5)\\inra.bin", "rb")
 A = readBin(long, integer(), size = 2, n = 1*67420, signed = TRUE)
 lot <- file("C:\\New folder (5)\\lat.img", "rb")
 B = readBin(lot, integer(), size = 2, n = 1*67420, signed = TRUE)
  wind <- file("C:\\Wind_WFD_200201.bin", "rb")
   C= readBin(wind, integer(), size = 2, n = 248*67420, signed = TRUE)  ##it
has 67420 columns  and 248 rows
  for (i in seq_along(C)){     
  for (i in (1:67420)) {
   M(A(i), B(i)) = C(i)
  }}
 for (i in seq_along(M)){
fileName <- sprintf("C:/New folder/glo_%d.flt", i)
writeBin(as.double(M[[i]]), fileName, size = 4)} ## for writing each row to
to a new file

--
View this message in context: http://r.789695.n4.nabble.com/write-to-M-using-row-and-columns-taken-from-A-and-B-with-values-from-C-tp4589197p4589197.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list