I have a RasterStack
with 3 layers each one of them containing 19 variables. Using writeRaster
I need to save specific variables into my directory while naming the saved files with the actual variable name and it's respective layer id.
If one were to take the variables one by one in each layer...
writeRaster(myRasterStack$var1.1, "var1.1.grd", format = "raster")
var1
indicating the actual name of the variable in the raster object and .1
it's respective layer.
I'm working on the following loop.
variables <- as.factor(c("var1.1", "var8.1", "var1.2", "var8.2","var1.3", "var8.3"))
for (i in 1:length(variables))
{
writeRaster(myRasterStack$[i], filename = paste0("variables", i,"/data/.grd"), format = "raster")
}
What am I missing in the loop?