[R] mean of 3D arrays

2011-10-05 Thread Martin Batholdy
Hi, I have multiple three dimensional arrays. Like this: x1 - array(rnorm(1000, 1, 2), dim=c(10, 10, 10)) x2 - array(rnorm(1000, 1, 2), dim=c(10, 10, 10)) x3 - array(rnorm(1000, 1, 2), dim=c(10, 10, 10)) Now I would like to compute the mean for each corresponding cell. As a result I want to

Re: [R] mean of 3D arrays

2011-10-05 Thread R. Michael Weylandt michael.weyla...@gmail.com
(x1+x2+x3)/3 I'm not aware of a pmean function but it wouldn't be hard to homebrew one if you are comfortable with the ... argument I'll draft one up and send it along Michael Weylandt On Oct 5, 2011, at 9:00 AM, Martin Batholdy batho...@googlemail.com wrote: Hi, I have multiple three

Re: [R] mean of 3D arrays

2011-10-05 Thread R. Michael Weylandt michael.weyla...@gmail.com
As promised ### Untested pmean - function(...){ dotArgs - list(...) l - length(dotArgs) if( l == 0L ) stop(no arguments) temp - dotArgs[[1]] if ( l 1L ) {for(i in 2L:l) {temp - temp + dotArgs[[i]]}} temp/l } Clunky but gets the job done. Its still too early for me to

Re: [R] mean of 3D arrays

2011-10-05 Thread Dennis Murphy
Hi: There are a few ways to do this. If you only have a few arrays, you can simply add them and divide by the number of arrays. If you have a large number of such arrays, this is inconvenient, so an alternative is to ship the arrays into a list and use the Reduce() function. For your example, L

Re: [R] mean of 3D arrays

2011-10-05 Thread David Winsemius
On Oct 5, 2011, at 8:14 AM, R. Michael Weylandt michael.weyla...@gmail.com wrote: (x1+x2+x3)/3 I'm not aware of a pmean function but it wouldn't be hard to homebrew one if you are comfortable with the ... argument I'll draft one up and send it along pmean - function(lis)