summarise(mtcars, mean(disp))
summarise(group_by(mtcars, cyl), mean(disp))
summarise(group_by(mtcars, cyl), m = mean(disp), sd = sd(disp))
# With data frames, you can create and immediately use summaries
by_cyl <- mtcars %>% group_by(cyl)
by_cyl %>% summarise(a = n(), b = a + 1)
# You can't with data tables or databases
by_cyl_dt <- mtcars %>% dtplyr::tbl_dt() %>% group_by(cyl)
by_cyl_dt %>% summarise(a = n(), b = a + 1)
by_cyl_db <- src_sqlite(":memory:", create = TRUE) %>%
copy_to(mtcars) %>% group_by(cyl)
by_cyl_db %>% summarise(a = n(), b = a + 1)
Run the code above in your browser using DataLab