How can I get with dplyr the minimum (or average) value of each row on data.frame? I mean the same result as
apply(mydataframe, 1, mean) apply(mydataframe, 1, min)
I tried
mydataframe %>% rowwise() %>% mean
or
mydataframe %>% rowwise() %>% summarise(mean)
or other combinations, but I always get errors, I don’t know how to correctly.
I know that I can also use rowMeans, but there is no simple equivalent to "rowMin". There is also a matrixStats package, but most functions do not accept data.frames, only matrices.
If I want to calculate the minimum number of roles, I can use do.call (pmin, mydataframe) Is there something simple like this for the middle tier? [/ P>
do.call(mean, mydataframe)
doesn’t work, it seems to me that I need a pmean function or something more complex.
thanks
To compare the results, we could work on one example:
set.seed(124) df <- data.frame(A=rnorm(10), B=rnorm(10), C=rnorm(10))
source share