as.interval

0th

Percentile

Change an object to an interval.

Change an object to an interval.

Keywords
manip, classes, methods, chron
Usage
as.interval(x, origin)
Arguments
x
a duration (i.e. difftime), period, or numeric object that describes the length of the interval
origin
a POSIXt or Date object that describes when the interval begins
Details

as.interval changes duration (i.e. difftime), period and numeric objects to intervals that begin at the specified date-time. Numeric objects are first coerced to time spans equal to the numeric value in seconds.

as.interval can be used to create accurate transformations between period objects, which describe time spans in relative units, and duration objects, which describe timespans in exact units. To do this, however, an origin date- time must be supplied from which to measure the period. See as.duration, as.period.

Value

  • an interval object

See Also

interval, new_interval

Aliases
  • as.interval
Examples
diff <- new_duration(days = 31) #duration
as.interval(diff, as.POSIXct("2009-01-01"))
# 31 days beginning at 2009-01-01
as.interval(diff, as.POSIXct("2009-02-01"))
# 31 days beginning at 2009-02-01

per <- new_period(months = 1) #period
as.interval(per, as.POSIXct("2009-01-01"))
# 31 days beginning at 2009-01-01
as.interval(per, as.POSIXct("2009-02-01"))
# 28 days beginning at 2009-02-01
as.interval(3600, as.POSIXct("2009-01-01")) #numeric
# 1 hours beginning at 2009-01-01}
Documentation reproduced from package lubridate, version 0.1, License: GPL

Community examples

Looks like there are no examples yet.