Grouped data frames
group_by.RdCreate a data frame with grouping attributes.
Details
Subset operations $<-, [[<-,
[<-, and [
on a group_df will drop the grouping attributes. List-columns cannot
be grouped on.
Examples
#----------------------------------------------------------------------------
# group_by() examples
#----------------------------------------------------------------------------
library(bkdat)
df <- data.frame(a = c(1, 2, 3), b = c(1, 1, 2), c = c(1, 2, 3))
group_by(df, "a")
#> a b c
#> 1 1 1 1
#> 2 2 1 2
#> 3 3 2 3
group_by(df, "b")
#> a b c
#> 1 1 1 1
#> 2 2 1 2
#> 3 3 2 3
group_by(df, c("a", "b"))
#> a b c
#> 1 1 1 1
#> 2 2 1 2
#> 3 3 2 3
summarise(group_by(df, "b"), c(mean = "mean(a)"))
#> b c(mean = "mean(a)")
#> 1 1 mean(a)
#> 2 2 mean(a)