[R-sig-Geo] How to output the minimum and maximum value from rasterstack into csv/text file??

Andrew P Vitale vitale232 at gmail.com
Fri Dec 13 01:44:16 CET 2013


I think this is what you're going for:

library(raster)
r <- raster(nrow=5, ncol=5)
s <- stack( sapply(1:5, function(i) setValues(r, rnorm(ncell(r), i, 3) )) )

min <- cellStats(s, 'min')
max <- cellStats(s, 'max')
mean <- cellStats(s, 'mean')

df <- data.frame(min, max, mean)

write.csv(df, 'df.csv')

On 12/12/2013 2:11 PM, Eddie Smith wrote:
> Hi guys,
>
> library(raster)
> r <- raster(nrow=5, ncol=5)
> s <- stack( sapply(1:5, function(i) setValues(r, rnorm(ncell(r), i, 3) )) )
>
> class       : RasterStack
> dimensions  : 5, 5, 25, 5  (nrow, ncol, ncell, nlayers)
> resolution  : 72, 36  (x, y)
> coord. ref. : +proj=longlat +datum=WGS84 +ellps=WGS84 +towgs84=0,0,0
> names       :    layer.1,    layer.2,    layer.3,    layer.4,    layer.5
> min values  : -4.2962007, -2.6573262, -1.3929480,  0.1079140, -0.1711899
> max values  :   5.888370,   7.654831,  10.222458,  10.486516,   9.694796
>
> How do I export the minimum and maximum values for all layers? (I have few
> hundreds of layers in a rasterstack). Is it also possible to get the mean
> values?
>
> Thank you.
>
> 	[[alternative HTML version deleted]]
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo



More information about the R-sig-Geo mailing list