as.second: Interconvert Nominal Time Units

Description Usage Arguments Details Value Author(s) References See Also Examples

Description

Perform standard conversions among various common time units.

Usage

1
2
3
4
5
6
7

Arguments

x

numeric

...

ignored

Details

The functions listed above are generic. Methods exist, either explictly or implicitly, for objects classified to represent second, minute, hour, day, week, month, and year. All these objects are subclasses of "duration"; as.<n>.duration serves wherever explicit methods are omitted. For each generic, methods exist for class "numeric". For each class, methods exist for the generics "format" and "print".

The strategy for time unit conversion is to classify a numeric vector according to some unit, and then coerce that object to some other class. Thus, as.day(7) is not particularly interesting, but as.week(as.day(7)) yields 1.

Conversions use 60 seconds per minute, 60 minutes per hour, 24 hours per day, 7 days per week, 28 days per month, and 365.25 days per year. Currently, no other relationships are specified. Note that 12 nominal months does not make a full year. This is experimental, and may change in future versions.

The duration classes are also subclasses of timeline, which exists to support addition and subtraction of durations and timepoints. See examples here, and at timeline. You cannot add two timepoints, nor can you subtract a timepoint from a non-timepoint. When one argument is a timepoint, the other is coerced using as.second, and the result is the timepoint class. For two durations, the second value is coerced to the class of the first, with a message, if necessary. Otherwise, if only one argument is a duration, the other is coerced to that class. Negative durations are allowed.

Value

an S3 "num" object with class c(n, 'duration','timeline','numeric'), where ā€˜nā€™ is "second", "minute", "hour", "day", "week", "month", or "year", as implied.

Author(s)

Tim Bergsma

References

http://metrumrg.googlecode.com

See Also

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
as.year(as.month(12))
as.year(as.day(365.25))
as.second(as.year(1))
as.month(2) + as.week(2)
as.week(2) + as.month(1)
as.month(2) - as.week(2)
as.week(2) - as.month(1)
as.week(2) + 1
as.week(2) - 1
2 + as.week(1)
2 - as.week(1)
class(c(as.day(1),as.day(2)))
class(as.day(1:5)[3])
class(as.day(1:5)[[3]])
class(seq(from=as.day(2),to=as.day(6)))
class(rep(as.day(1),5))

metrumrg documentation built on May 2, 2019, 5:55 p.m.