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

David Winsemius dwinsemius at comcast.net
Thu May 24 18:07:52 CEST 2012


On May 24, 2012, at 11:51 AM, Jonsson wrote:

> Dear All,
> The code given bellow is to extract  values of one region and write  
> that to
> a text file(there are 365 binary files in the directory).
> The problem which I am facing is that all my files are binary with  
> size of
> 360 rows and 720 columns.
> I specified that in this line:    file2<- 
> matrix(data=file,ncol=720,nrow=360)
> but I got an error : Error in mean(file2[X, Y], na.rm = TRUE) :  
> subscript
> out of bounds.
> and then I rewrote the above line as
> :file2<-matrix(data=file,ncol=360,nrow=720.I put ncol=360 and nrows  
> =720
> which is not right.But that worked and I didn't get any  
> error.however,the
> results were not correct.
> Any help please
>
> dir1<- list.files("C:\\Users\\aalyaari\\Desktop\\New folder
> (10)\\Climate_Rad_f_GAMMA_%d.img", full.names = TRUE)
> listfile<-dir()
> for (i in c(1:365)) {
>      conne <- file(listfile[i], "rb")
>      file<- readBin(conne, double(), size=4,  n=720*360, signed=T)
>     file2<-matrix(data=file,ncol=720,nrow=360)
> 	extract[i]<-mean(file2[X,Y],na.rm=TRUE)
>      close(conne)
> write.table(extract,"C:\\Users\\aalyaari\\Desktop\\New folder
> (10)\\sam.txt")}

Please do not cross post to SO and Rhelp. (See Posting Guide.)

(But if you do, rhelp generally expects reproducible examples which  
this is not.)

-- 
David Winsemius, MD
West Hartford, CT



More information about the R-help mailing list