我试图通过两个值(名称和p23)对数据进行排序,然后对p23的类似值求和 . 我还是dplyr的新手,我不知道下一步该做什么
install.packages("dplyr")
library(dplyr)
# library(tidyr)
df<-data.frame(
name=c("a","b","b","c","b"),
p23=c(2,2,3,3,2),
data=c(0,1,2,3,4)
)
res<-df %>% group_by(name,p23) #now what?
目标
a 2 0 #this is also an average but there is only one value
b 2 2.5 #this is the average of the two b's in p23 with value 2
b 3 2
c 3 3
1 回答