as_period {grates} | R Documentation |
Coerce an object to period
Description
as_period()
is a generic for coercing input in to <grates_period>
.
Usage
as_period(x, n, ...)
## Default S3 method:
as_period(x, n = 1L, offset = 0L, ...)
## S3 method for class 'Date'
as_period(x, n = 1L, offset = 0L, ...)
## S3 method for class 'POSIXt'
as_period(x, n = 1L, offset = 0L, ...)
## S3 method for class 'character'
as_period(x, n = 1L, offset = 0L, ...)
## S3 method for class 'factor'
as_period(x, n = 1L, offset = 0L, ...)
Arguments
x |
An R object:
|
n |
Number of days that are being grouped. |
... |
Only used For character input where additional arguments are passed through
to |
offset |
Value you wish to start counting periods from relative to the Unix Epoch:
|
Value
A <grates_period>
object.
Note
Internally grates_period
objects are stored as the integer number, starting
at 0L, of periods since the Unix Epoch (1970-01-01) and a specified offset.
Here periods are taken to mean groupings of n
consecutive days.
See Also
as.Date()
Examples
as_period("2019-05-03")
as_period("2019-05-03", n = 2, offset = 1)
as_period(as.POSIXct("2019-03-04 01:01:01", tz = "America/New_York"), n = 10)
as_period(as.Date("2020-03-02"), n = 2L, offset = as.Date("2020-03-01"))