R users,
This probably involves a simple incantation of one of the flavors of apply...
that I can't yet figure out. Consider a list of data frames. I'd like to apply
a function (mean) across the list and return a dataframe of the same dimensions
where each cell represents the mean of that cell
Hi,
Try this,
do.call(`+`, x) / length(x)
HTH,
baptiste
On 24 November 2010 20:37, Tim Howard tghow...@gw.dec.state.ny.us wrote:
R users,
This probably involves a simple incantation of one of the flavors of apply...
that I can't yet figure out. Consider a list of data frames. I'd like to
try this:
DF.lis - list(
one = data.frame(x = c(1,2,3), y = c(1,2,2), z = c(3,1,1)),
two = data.frame(x = c(2,5,2), y = c(2,3,1), z = c(4,1,2))
)
Reduce(+, DF.lis) / length(DF.lis)
I hope it helps.
Best,
Dimitris
On 11/24/2010 8:37 PM, Tim Howard wrote:
R users,
This probably
Hi Tim,
It may not be possible, but if you can use an array, it is super easy:
## convert to array
Sue - array(unlist(x), dim = c(3, 3, 2))
## use apply() on first two dimensions (collapse across 3rd)
apply(X = Sue, MARGIN = c(1, 2), FUN = mean)
Cheers,
Josh
On Wed, Nov 24, 2010 at 11:37 AM,
Fabulous!
I'll start with trying out Reduce, and then explore do.call or converting it to
an array if I need to.
Thank you Dimitris, Baptiste, and Josh for the very quick help!
Best,
Tim
Dimitris Rizopoulos d.rizopou...@erasmusmc.nl 11/24/2010 2:43 PM
try this:
DF.lis - list(
one =
5 matches
Mail list logo