Calculate the mean by group

后端 未结 5 1011
没有蜡笔的小新
没有蜡笔的小新 2020-11-21 04:42

I have a large data frame that looks similar to this:

df <- data.frame(dive = factor(sample(c("dive1","dive2"), 10, replace=TRUE)),
            


        
5条回答
  •  忘了有多久
    2020-11-21 05:21

    2015 update with dplyr:

    df %>% group_by(dive) %>% summarise(percentage = mean(speed))
    Source: local data frame [2 x 2]
    
       dive percentage
    1 dive1  0.4777462
    2 dive2  0.6726483
    

提交回复
热议问题