Count number of rows within each group

后端 未结 14 2507
夕颜
夕颜 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:54

    An old question without a data.table solution. So here goes...

    Using .N

    library(data.table)
    DT <- data.table(df)
    DT[, .N, by = list(year, month)]
    

提交回复
热议问题