[R-sig-Geo] Calculating descriptive stats from many maps

Tomislav Hengl T.Hengl at uva.nl
Mon Feb 9 17:33:51 CET 2009


Dear Rainer,

This is of course possible in R, and can be done in several ways:

1) for example, you can derive the average value using the rowSums function:

> maps$Nsum <- rowSums(maps at data, na.rm=T, dims=1)
> maps$avg <- maps$Nsum/(length(names(meuse.grid at data))-1)

You could also loop the sd, mean and quantile function over a range of cells:

> for(i in length(names(maps at data))) {
> maps at data$sd[i] <- sd(maps at data[i,])
> maps at data$mean[i] <- mean(maps at data[i,])
...
> }

This could take a lot of time!

2) if your maps are rather large, try also using the SAGA function:

> rsaga.get.usage(lib = "geostatistics_grid", module=5)
SAGA CMD 2.0.3
library path:   C:/Progra~1/saga_vc/modules
library name:   geostatistics_grid
module name :   Statistics for Grids

This is probably the fastest method you can use.

HTH

T. Hengl

> -----Original Message-----
> From: r-sig-geo-bounces at stat.math.ethz.ch [mailto:r-sig-geo-bounces at stat.math.ethz.ch] On Behalf
> Of Rainer M Krug
> Sent: Monday, February 09, 2009 4:58 PM
> To: R-sig-Geo at stat.math.ethz.ch
> Subject: [R-sig-Geo] Calculating descriptive stats from many maps
> 
> Hi
> 
> I have 25000 maps, generated by simulation predictions, covering the
> same area, and would like to calculate some descriptive stats, like
> mean, standard deviation, median, quartiles of all cells, to create a
> "variability map".
> 
> Is there an easy way of doing this in R?
> 
> Thanks,
> 
> Rainer
> 
> --
> Rainer M. Krug, PhD (Conservation Ecology, SUN), MSc (Conservation
> Biology, UCT), Dipl. Phys. (Germany)
> 
> Centre of Excellence for Invasion Biology
> Faculty of Science
> Natural Sciences Building
> Private Bag X1
> University of Stellenbosch
> Matieland 7602
> South Africa
> 
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at stat.math.ethz.ch
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo




More information about the R-sig-Geo mailing list