yearquarter_class | R Documentation |
<grates_yearquarter>
objects represent years and associated quarters
Internally they are stored as the number of quarters (starting at 0) since
the Unix Epoch (1970-01-01).
yearquarter(year = integer(), quarter = integer())
as_yearquarter(x, ...)
## Default S3 method:
as_yearquarter(x, ...)
## S3 method for class 'Date'
as_yearquarter(x, ...)
## S3 method for class 'POSIXt'
as_yearquarter(x, ...)
## S3 method for class 'character'
as_yearquarter(x, ...)
## S3 method for class 'factor'
as_yearquarter(x, ...)
new_yearquarter(x = integer())
is_yearquarter(xx)
year |
Vector representing the year associated with
|
quarter |
Vector representing the quarter associated with
|
x , xx |
R objects. |
... |
Only used for character input where additional arguments are passed through
to |
yearquarter()
is a constructor for <grates_yearquarter>
objects. It takes
a vector of year and a vector of quarter values as inputs. Length 1 inputs
will be recycled to the length of the other input and double
vectors will
be converted to integer via as.integer(floor(x))
.
as_yearquarter()
is a generic for coercing input in to <grates_yearquarter>
.
Character input is first parsed using as.Date()
.
POSIXct and POSIXlt are converted with their timezone respected.
new_yearquarter()
is a minimal constructor for <grates_yearquarter>
objects aimed at developers. It takes, as input, the number of quarters
(starting at 0) since the Unix Epoch, that you wish to represent.
double
vectors will again be converted to integer via as.integer(floor(x))
.
A <grates_yearquarter>
object.
# date coercion
as_yearquarter(Sys.Date())
# POSIXt coercion
as_yearquarter(as.POSIXct("2019-03-04 01:01:01", tz = "America/New_York"))
# character coercion
as_yearquarter("2019-05-03")
# construction
yearquarter(year = 2000, quarter = 3)
# direct construction
d <- seq.Date(from = as.Date("1970-01-01"), by = "quarter", length.out = 4)
stopifnot(
identical(
as_yearquarter(d),
new_yearquarter(0:3)
)
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.