Which groups in the data.table have a corresponding set of dates

Example

set.seed(2016)
dt <- data.table(
  Grp = sample(1000, 1000000, replace=TRUE),
  Date = as.Date("2016-1-1") + sample(365, 1000000, replace=TRUE)
)
dt <- unique(dt)

dt[order(Grp, Date)]
         Grp       Date
     1:    1 2016-01-02
     2:    1 2016-01-03
     3:    1 2016-01-05
     4:    1 2016-01-06
     5:    1 2016-01-07
    ---                
341526: 1000 2016-12-27
341527: 1000 2016-12-28
341528: 1000 2016-12-29
341529: 1000 2016-12-30
341530: 1000 2016-12-31

How do I find out which groups (if any) use the same set of dates? I think I can dcastdata and then search for the relevant rows, but is there a better way?

+4
source share

Source: https://habr.com/ru/post/1654193/


All Articles