subsample raster in r

To subsample a raster in R, we can use the raster package. The raster package is widely used for working with raster data because of its efficient and fast processing.

First, install and load the raster package:

install.packages("raster")
library("raster")
45 chars
3 lines

Next, we can load the raster file:

r <- raster("path_to_raster_file")
35 chars
2 lines

To subsample the raster, we can use the resample() function. For example, if we want to reduce the resolution of the raster to half, we can use the following code:

r_subs <- resample(r, res = res(r) * 2)
40 chars
2 lines

The res argument specifies the desired resolution of the output raster. In this case, we multiply the original resolution by 2 to reduce it to half.

We can then save the subsampled raster as follows:

writeRaster(r_subs, filename = "path_to_output_file")
54 chars
2 lines

This will save the subsampled raster to the specified file location.

gistlibby LogSnag