Count number of rows within each group

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

    The simple option to use with aggregate is the length function which will give you the length of the vector in the subset. Sometimes a little more robust is to use function(x) sum( !is.na(x) ).

提交回复
热议问题