ints <- c(
new_interval(ymd("2001-01-01"), ymd("2002-01-01")),
new_interval(ymd("2001-01-01"), ymd("2004-01-01"))
)
as.period(ints)
# [1] "1y 0m 0d 0H 0M 0S" "3y 0m 0d 0H 0M 0S"
as.period converts correctly to the specified time units if the variable is a scalar:
as.period(ints[1], "days")
# [1] "365d 0H 0M 0S"
But it shows an error if it's a vector:
as.period(ints, "days")
# Error in initialize(value, ...) :
# invalid names for slots of class “Period”: day1, day2
I would prefer not having to do something like
ans <- Map(function(x) as.period(x, "days"), ints)
ans
# [[1]]
# [1] "365d 0H 0M 0S"
#
# [[2]]
# [1] "1095d 0H 0M 0S"
And, also, why does this happen?
Should be necessary to implement the unlist function for Interval objects?
(Thanks in advance.)
as.periodconverts correctly to the specified time units if the variable is a scalar:But it shows an error if it's a vector:
I would prefer not having to do something like
And, also, why does this happen?
Should be necessary to implement the
unlistfunction for Interval objects?(Thanks in advance.)