从dplyr应用group_by函数并使用%.%运算符后,如何访问分组数据
例如,如果我想拥有每个分组数据的第一行,那么我可以使用plyr包作为
ddply(iris,.(Species),function(df){
df[1,]
})
#output
# Sepal.Length Sepal.Width Petal.Length Petal.Width Species
#1 5.1 3.5 1.4 0.2 setosa
#2 7.0 3.2 4.7 1.4 versicolor
#3 6.3 3.3 6.0 2.5 virginica
Run Code Online (Sandbox Code Playgroud)