How can I get with dplyr the minimum (or mean) value of each row on a data.frame?
I mean the same result as
apply(mydataframe, 1, mean)
apply(mydataframe, 1, min)
I've tried
mydataframe %>% rowwise() %>% mean
or
mydataframe %>% rowwise() %>% summarise(mean)
or other combinations but I always get errors, I don't know the proper way.
I know that I could also use rowMeans, but there is no simple "rowMin" equivalent.
There also exist a matrixStats package but most functions don't accept data.frames, only matrixes.
If I want to calculate the min rowwise I could use
do.call(pmin, mydataframe)
Is there anything simple like this for the rowwise mean?
do.call(mean, mydataframe)
doesn't work, I guess I need a pmean function or something more complex.
Thanks
In order to compare the results we could all work on the same example:
set.seed(124)
df <- data.frame(A=rnorm(10), B=rnorm(10), C=rnorm(10))
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…