R dplyr rowwise mean or min and other methods?

后端 未结 5 1291
情书的邮戳
情书的邮戳 2020-12-01 19:23

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         


        
5条回答
  •  一向
    一向 (楼主)
    2020-12-01 19:53

    How about this?

    library(dplyr)
    as.data.frame(t(mtcars)) %>%
      summarise_all(funs(mean))
    

    For extra clarity, you could add another t() at the end:

    as.data.frame(t(mtcars)) %>%
      summarise_all(funs(mean)) %>%
      t()
    

提交回复
热议问题