period_class | R Documentation |
<grates_period>
objects represent groupings of n
consecutive days
calculated relative to an offset
. It is useful for when you wish to group
an arbitrary number of dates together (e.g. 10 days).
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, ...)
new_period(x = integer(), n = 1L, offset = 0L)
is_period(xx)
x , xx |
R objects. For For |
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:
|
Internally grates_period
objects are stored as the integer number, starting
at 0, of periods since the Unix Epoch (1970-01-01) and a specified offset. Here
periods are taken to mean groupings of n
consecutive days. For storage and
calculation purposes, offset
is scaled relative to n
(i.e. offset <- offset %% n
) and values of x
stored relative to this
scaled offset.
as_period()
is a generic for coercing input in to <grates_period>
objects.
It is the recommended way for constructing period objects as it allows the
offset
to be specified as a date
(rather than an integer value relative to
the Unix Epoch).
Character input is first parsed using as.Date()
.
POSIXct and POSIXlt are converted with their timezone respected.
new_period()
is a minimal constructor for <grates_period>
objects aimed at developers. It takes, as input, the number of periods since
the Unix Epoch and the specified offset
. double
vectors will
be converted via as.integer(floor(x))
.
A <grates_period>
object.
# coercion from date
dat <- as.Date("2012-12-01")
as_period(dat + 0:3, n = 2, offset = dat)
# direct construction
new_period(1:10)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.