Count number of rows within each group

后端 未结 14 2490
夕颜
夕颜 2020-11-21 05:01

I have a dataframe and I would like to count the number of rows within each group. I reguarly use the aggregate function to sum data as follows:



        
14条回答
  •  梦如初夏
    2020-11-21 05:39

    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.

提交回复
热议问题