I have several hundred "A" rasters, numbered from 001_A.tif to 100_A.tif.
I also have several hundred "B" rasters, numbered from 001_B.tif to 100_B.tif.
I want to multiply them like this:
001_A * 001_B = 001_result 002_A * 002_B = 002_result 003_A * 003_B = 003_result . . . I have a loop in R which works fine, but it is relatively slow:
library(raster) A_Files <- list.files(pattern="A.tif") # files A All_A <- unique(A_Files) B_Files <- list.files(pattern="B") # files B All_B <- unique(B_Files) for (i in 1:100) { A.i <- All_A[i] B.i <- All_B[i] Raster_A.i <- raster(A.i) # create rasters from files A Raster_B.i <- raster(B.i) # create rasters from files B Result.i <- (Raster_A.i * Raster_B.i) # multiplying A by B writeRaster(Result.i, paste(A.i, "_result.tif", sep = ""), datatype='FLT4S', overwrite=TRUE) # write results in .tif format with the name "001_A_result.tif" } Is there a way to speed it up?