[R] mean and array

J.R. Lockwood lockwood at rand.org
Tue Jul 2 15:03:27 CEST 2002


> 
> I have an array, one say ar, with 3 dimensions.
> dim(ar)
>  >200   3   4
> I would like to calculate the mean on the third dimension.
> mean(ar[1,1,]),mean(ar[1,2,]) etc..., mean[200,3,].
> 
> How can i do this ?

apply(ar,c(1,2),mean)

will produce a (200 X 3) matrix of means averaged over the third
dimension.


J.R. Lockwood
412-683-2300 x4941
lockwood at rand.org
http://www.rand.org/methodology/stat/members/lockwood/

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list