Description Usage Arguments Value See Also Examples
Turn dates into year months/year quarters/years.
1 2 3 4 5 | year_month(x, shift = 0, frac = 0)
year_quarter(x, shift = 0, frac = 0)
year(x, shift = 0, frac = 0)
|
x |
A date, or something that can be coerced into one. |
shift |
Number of months to shift up/down dates in x (0 by default). |
frac |
Should calendar periods be formatted as the first day in a period (0, the default), the last day (1), or some point in between? |
A vector of dates.
See complete_quarters
for an application, and calendar_period
for non-standard calendar periods.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | # Turn dates into year-months
x <- as.Date(c('2018-01-15', '2018-01-03', '2018-02-24'))
year_month(x)
# Turn year-months into year-quarters
x <- as.Date(c('2018-01-01', '2018-02-01', '2018-04-01'))
year_quarter(x)
# Format as the last day in a quarter
year_quarter(x, frac = 1)
## Not run:
# This can also be done with zoo
library(zoo)
as.Date(as.yearqtr(x))
as.Date(as.yearqtr(x), frac = 1)
## End(Not run)
# Find periods one month ago
match(year_month(x, -1), year_month(x))
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.