I am calculating the correlation between two data sets but due to the big size of the data (10 GB) while my RAM is only 6 GB I am facing a memory issue. I wonder how can to chunk my code?
dir1 <- list.files("D:sdr", "*.bin", full.names = TRUE)
dir2 <- list.files("D:dsa", "*.img", full.names = TRUE)
file_tot<-array(dim=c(1440,720,664,2))
for(i in 1:length(dir1)){
file_tot[,,i,1] <- readBin(dir1[i], numeric(), size = 4 ,n = 1440 * 720 , signed = T)
file_tot[,,i,2] <- readBin(dir2[i], integer(), size = 2 ,n = 1440 * 720 , signed = F)
file_tot[,,i,2] <- file_tot[,,i,2]*0.000030518594759971
file_tot[,,i,2][file_tot[,,i,2] == 9999 ] <- NA
}
result<-apply(file_tot,c(1,2),function(x){cor(x[,1],x[,2])})
But got this error:
Error: cannot allocate vector of size 10.3 Gb
In addition: Warning messages:
1: In file_tot[, , i, 1] <- readBin(dir1[i], numeric(), size = 4, n = 1440 * :
Reached total allocation of 16367Mb: see help(memory.size)
2: In file_tot[, , i, 1] <- readBin(dir1[i], numeric(), size = 4, n = 1440 * :
Reached total allocation of 16367Mb: see help(memory.size)
3: In file_tot[, , i, 1] <- readBin(dir1[i], numeric(), size = 4, n = 1440 * :
Reached total allocation of 16367Mb: see help(memory.size)
4: In file_tot[, , i, 1] <- readBin(dir1[i], numeric(), size = 4, n = 1440 * :
Reached total allocation of 16367Mb: see help(memory.size)