[R] How to calculate the spatial correlation of several files?

Jonsson amen.alyaari at Bordeaux.inra.fr
Mon Dec 3 16:15:54 CET 2012


    dir1 <- list.files("C:\\Users\\aalyaari\\Desktop\\cor", "*.bin",
full.names = TRUE)
    dir2 <- list.files("C:\\Users\\aalyaari\\Desktop\\cor2", "*.bin",
full.names = TRUE)
    results <- list()
        for (.files in dir1){   # read in the 365 files as a vector of
numbers for dir1
        file1 <- do.call(rbind,(lapply(.files, readBin  , integer() , size =
2 ,
                                    n = 360 * 720 , signed = T)))    }
        for (.files in dir2){   # read in the 365 files as a vector of
numbers for dir2
        file2<- do.call(rbind,(lapply(.files, readBin  , integer() , size =
2 , 
                        n = 360 * 720 , signed = T)))   }
       # Now each file  in both directories is a vector. I am not sure how
to tell R to correlate the first column in dir1 to the correspond column
from dir2. we will finally get only one spatial correlation map.
I tried to this:
 # calculate the  correlation so we will get a correlation map
    for (.files in seq_along(dir1)){              
        results[[length(results) + 1L]]<- cor(file1 ,file2)
        }
I got error:Error in cor(file1, file2) : allocMatrix: too many elements
specified`





--
View this message in context: http://r.789695.n4.nabble.com/How-to-calculate-the-spatial-correlation-of-several-files-tp4651888.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list