How to find number of unique ids corresponding to each date in a data drame

前端 未结 3 771
一整个雨季
一整个雨季 2021-01-24 07:28

I have a data frame that looks like this:

      date         time              id            datetime    
1 2015-01-02 14:27:22.130 999000000007628 2015-01-02 14         


        
3条回答
  •  执笔经年
    2021-01-24 08:25

    You can use the uniqueN function from data.table:

    library(data.table)
    setDT(df)[, uniqueN(id), by = date]
    

    or (as per the comment of @Richard Scriven):

    aggregate(id ~ date, df, function(x) length(unique(x)))
    

提交回复
热议问题