row - R dplyr rowwise mean or min and other methods? -


how can dplyr minimum (or mean) value of each row on data.frame? mean 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 errors, don't know proper way.

i know use rowmeans, there no simple "rowmin" equivalent. there exist matrixstats package functions don't accept data.frames, matrixes.

if want calculate min rowwise use
do.call(pmin, mydataframe) there simple rowwise mean?

do.call(mean, mydataframe)  

doesn't work, guess need pmean function or more complex.

thanks

in order compare results work on same example:

set.seed(124) df <- data.frame(a=rnorm(10), b=rnorm(10), c=rnorm(10)) 

i suppose trying accomplish:

df <- data.frame(a=rnorm(10), b=rnorm(10), c=rnorm(10))  library(dplyr) df %>% rowwise() %>% mutate(min = min(a, b, c), mean = mean(c(a, b, c)))  #                      b           c        min        mean # 1   1.3720142  0.2156418  0.61260582  0.2156418  0.73342060 # 2  -1.4265665 -0.2090585 -0.05978302 -1.4265665 -0.56513600 # 3   0.6801410  1.5695065 -2.70446924 -2.7044692 -0.15160724 # 4   0.0335067  0.8367425 -0.83621791 -0.8362179  0.01134377 # 5  -0.2068252 -0.2305140  0.23764322 -0.2305140 -0.06656532 # 6  -0.3571095 -0.8776854 -0.80199141 -0.8776854 -0.67892877 # 7   1.0667424 -0.6376245 -0.41189564 -0.6376245  0.00574078 # 8  -1.0003376 -1.5985281  0.90406055 -1.5985281 -0.56493504 # 9  -0.8218494  1.1100531 -1.12477401 -1.1247740 -0.27885677 # 10  0.7868666  0.6099156 -0.58994138 -0.5899414  0.26894694 

Comments

Popular posts from this blog

python - pip install -U PySide error -

arrays - C++ error: a brace-enclosed initializer is not allowed here before ‘{’ token -

cytoscape.js - How to add nodes to Dagre layout with Cytoscape -