I\'m trying to use dplyr to summarize a dataset based on 2 groups: \"year\" and \"area\". This is how the dataset looks like:
Year Area Num 1 2000 Area 1 99
We can use data.table
data.table
library(data.table) setDT(df)[, .(avg = mean(Num)) , by = .(Year, Area)]
Is this what you are looking for?
library(dplyr) df <- group_by(df, Year, Area) df <- summarise(df, avg = mean(Num))