If your trying the aggregate solutions above and you get the error:
invalid type (list) for variable
Because you're using date or datetime stamps, try using as.character on the variables:
aggregate(x ~ as.character(Year) + Month, data = df, FUN = length)
On one or both of the variables.