dir1和dir2两个目录共有365个二进制文件,格式相同,byte,extend等...
下面给出的代码将 dir1 和 dir2 作为向量读取,然后计算相关性。基本上我想得到相关图,我们只计算每个网格像素的R值。假设我们要计算 dir1 和 dir2 之间的全局相关图,我们有来自 dir1 和 dir2 的每个像素的两列数据,可以计算该像素的 R 值,然后简单地对全局像素进行循环。
dir1 <- list.files("C:\\cor", "*.bin", full.names = TRUE)
dir2 <- list.files("C:\\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)))
}
# calculate the correlation so we will get a correlation map
for (.files in seq_along(dir1)){
results[[length(results) + 1L]]<- cor(file1 ,file2)
}
我收到了这个错误:Error in cor(file1, file2) : allocMatrix: too many elements specified