[R] R does not recognise columns and rows as they are supposed to be

Jonsson amen.alyaari at Bordeaux.inra.fr
Fri May 25 18:36:04 CEST 2012


The trick may be behind not reading the files properly is that  all my 365
files donot have the same name. for example:
files from number 1 to number9 are named for the first month: 
 
SWdown_200101_01.img   
SWdown_200101_09.img   

files from number 10 to number30 are named: 

 SWdown_200101_10.img
SWdown_200101_30.img

 And so on for the second month:
files from number 1 to number9 are named: 
 
SWdown_200102_01.img   
SWdown_200102_09.img   

files from number 10 to number30 are named: 

 SWdown_200102_10.img
SWdown_200102_30.img

and in my code I just set the dierctory:   dir1<-
list.files("C:\\Users\\aalyaari\\Desktop\\New folder (11)\\", "*.img",
full.names = TRUE).

 assuming that R would read files in order.But I do not really know if this
right or I shall specify the names.


X<-(82:85) ; Y<-(364:367) #####   for sellected region 
 extract <- double() 
 dir1<- list.files("C:\\Users\\aalyaari\\Desktop\\New folder (11)\\",
"*.bin", full.names = TRUE)
 for (i in 1:365) { 
      conne <- file(dir1[i], "rb") 
      file1<- readBin(conne, numeric(),size=4,  n=360*720, endian="little") 
    file2<-matrix(data=file1,ncol=720,nrow=360) 
   extract[i]<-mean(file2[X,Y],na.rm=TRUE) 
    close(conne) } 
 write.table(as.double(extract),"C:\\Users\\aalyaari\\Desktop\\New folder
(10)\\new6.txt") 



--
View this message in context: http://r.789695.n4.nabble.com/R-does-not-recognise-columns-and-rows-as-they-are-supposed-to-be-tp4631217p4631352.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list