Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.Sign up
unique() for Interval? #315
unique() doesn't appear to be defined for class Interval, yet it silently runs and produces results that (I think) don't make sense.
foo <- Sys.time() + days(1:4) ints <- rep(interval(head(foo, -1), tail(foo, -1)), 2) ## each interval is the same _duration_, and unique(ints) simply returns the unique durations (in seconds). ## would (reasonably) expect the 3 unique _intervals_, instead. unique(ints) ##  86400
quick add on why this could be useful: stratification by interval, e.g. by creating interval factors:
## continuing the example code from above... factor(ints) ##  <NA> <NA> <NA> <NA> <NA> <NA> ## Levels: 86400 foo <- data.frame(x = 1:6, ints = ints) ## if dlply-ing over ints, would expect a length-3 vector of 2s... instead it's a length-1 vector of 6: unlist(dlply(foo, .(ints), nrow))