library(dplyr, warn.conflicts = FALSE)
db <- memdb_frame(g = c(1, 1, 1, 2, 2), x = c(4, 3, 6, 9, 2))
db %>%
group_by(g) %>%
summarise(n()) %>%
show_query()
db %>%
group_by(g) %>%
mutate(x2 = x / sum(x, na.rm = TRUE)) %>%
show_query()
Run the code above in your browser using DataLab