I want to obtain the union of many (more than 2) intervals:
df <- data.frame(id=c(1, 2, 3),
interval=c(
new_interval(ymd("2001-01-01"), ymd("2002-01-01")),
new_interval(ymd("2001-01-01"), ymd("2004-01-01")),
new_interval(ymd("2001-02-01"), ymd("2002-01-01"))
))
df
# id interval
#1 1 2001-01-01 UTC--2002-01-01 UTC
#2 2 2001-01-01 UTC--2004-01-01 UTC
#3 3 2001-02-01 UTC--2002-01-01 UTC
lubridate::union(lubridate::union(df$interval[1], df$interval[2]),
df$interval[3])
# [1] 2001-01-01 UTC--2004-01-01 UTC
That's the correct result.
But why lubridate::union does not work with Reduce?
Reduce(lubridate::union, df$interval )
# [1] 31536000 94608000 28857600
The intervals objects seem to get converted to numeric too son (before applying the union).
Related to: http://stackoverflow.com/questions/32944273/lubridate-how-to-calculate-the-union-of-many-intervals
I want to obtain the union of many (more than 2) intervals:
That's the correct result.
But why lubridate::union does not work with Reduce?
The intervals objects seem to get converted to numeric too son (before applying the union).
Related to: http://stackoverflow.com/questions/32944273/lubridate-how-to-calculate-the-union-of-many-intervals