This code given below (developed by stackoverflow users) will read a variable from a netcdf file and write it as an envi file.
This code is working fine but I have several netcdf files like this one and I want to make a loop to do this for all files in the directory.
The files are stored in a directory whose path is
d <- flip(t(d), direction = "x")
rf <- writeRaster(d, filename="last.envi", overwrite=TRUE)
I tried this:
for(i in 1:length(a)){
d <- raster(a[i], varname = "soil_moisture_c")
rf <- writeRaster(d[[i]], filename="%d.envi", overwrite=TRUE)
}
but got this error
Error in function (classes, fdef, mtable) :
unable to find an inherited method for function ‘writeRaster’ for signature ‘"numeric", "character"’