lubridate (version 0.2.4)

as.duration: Change an object to a duration (difftime).

Description

Change an object to a duration (difftime).

Usage

as.duration(x)

Arguments

x
an interval, period, or numeric object

Value

  • a duration object

Details

as.duration changes interval, period and numeric objects to duration objects. Numeric objects are changed to duration objects with the seconds unit equal to the numeric value.

Durations are exact time measurements, whereas periods are relative time measurements. See periods. The length of a period depends on when it occurs. Hence, a one to one mapping does not exist between durations and periods. When used with a period object, as.duration provides an inexact estimate of the length of the period; each time unit is assigned its most common number of seconds. Periods with a months unit cannot be coerced to durations because of the variability of month lengths. For an exact transformation, first transform the period to an interval with as.interval.

See Also

duration, new_duration

Examples

Run this code
span <- new_interval(ymd("2009-01-01"), ymd("2009-08-01")) #interval
# 2009-01-01 -- 2009-08-01 
as.duration(span)
# 18316800s (212d)
as.duration(10) # numeric
# 10s}

Run the code above in your browser using DataCamp Workspace