Skip to content
Fetching contributors…
Cannot retrieve contributors at this time
71 lines (66 sloc) 2.33 KB
\title{Change an object to a period.}
as.period(x, unit, ...)
\item{x}{an interval, difftime, or numeric object}
\item{unit}{A character string that specifies which time
units to build period in. unit is only implemented for
the as.period.numeric method and the as.period.interval
method. For as.period.interval, as.period will convert
intervals to units no larger than the specified unit.}
\item{...}{additional arguments to pass to as.period}
a period object
as.period changes Interval, Duration, difftime and
numeric class objects to Period class objects with the
specified units.
Users must specify which time units to measure the period
in. The exact length of each time unit in a period will
depend on when it occurs. See \code{\link{Period-class}}
and \code{\link{new_period}}. The choice of units is not
trivial; units that are normally equal may differ in
length depending on when the time period occurs. For
example, when a leap second occurs one minute is longer
than 60 seconds.
Because periods do not have a fixed length, they can not
be accurately converted to and from Duration objects.
Duration objects measure time spans in exact numbers of
seconds, see \code{\link{Duration-class}}. Hence, a one
to one mapping does not exist between durations and
periods. When used with a Duration object, as.period
provides an inexact estimate; the duration is broken into
time units based on the most common lengths of time
units, in seconds. Because the length of months are
particularly variable, a period with a months unit can
not be coerced from a duration object. For an exact
transformation, first transform the duration to an
interval with \code{\link{as.interval}}.
span <- new_interval(as.POSIXct("2009-01-01"), as.POSIXct("2010-02-02 01:01:01")) #interval
# 2009-01-01 CST--2010-02-02 01:01:01 CST
# "1y 1m 1d 1H 1M 1S"
as.period(span, units = "day")
"397d 1H 1M 1S"
\code{\link{Period-class}}, \code{\link{new_period}}
Something went wrong with that request. Please try again.