[R] How to calculate the spatial correlation of several files?
Rui Barradas
ruipbarradas at sapo.pt
Mon Dec 3 17:12:05 CET 2012
Hello,
Inline.
Em 03-12-2012 15:15, Jonsson escreveu:
> 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.
Are you sure? Shouldn't your file reading routines be
do.call(rbind, lapply(dir1, readBin, integer(), size = 2, n = 360 * 720,
signed = T))
do.call(rbind, lapply(dir2, readBin, integer(), size = 2, n = 360 * 720,
signed = T))
to lapply readBin to each file in dir1/dir2?
Anyway, to correlate the first row in file1 to the first row in file2,
etc, try
for (.f in seq_along(dir1)){
results[[.f]]<- cor(file1[, .f] ,file2[, .f])
}
Hope this helps,
Rui Barradas
> 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.
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
More information about the R-help
mailing list