I have several data frames, a
b
c
d
, each with the same column names. I want to find the mean and median of those data frames. In other words, construct new mean
and median
data frames that are the same size as a
, b
, etc.
I could use a couple of for
loops, but I bet there is a slick way of doing this using the R built-in functions that would be faster.
Following Josh Ulrich's answer, how about
library(abind)
apply(abind(a,b,c,d,along=3),c(1,2),median)
?
(Using rowMeans
on the appropriate slice will still be faster than apply
ing mean
... I think there is a rowMedians
in the Biobase
(Bioconductor) package if you really need speed?)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With