计算每个组内的行数
aggregate
df2 <- aggregate(x ~ Year + Month, data = df1, sum)
FUN
df2 <- aggregate(x ~ Year + Month, data = df1, count)
set.seed(2)df1 <- data.frame(x = 1:20, Year = sample(2012:2014, 20, replace = TRUE), Month = sample(month.abb[1:3], 20, replace = TRUE))
慕婉清6462132
慕后森