Description Usage Arguments Details Value See Also Examples
Identify which elements in a vector of dates correspond to complete quarter/years.
1 2 3 4 5 | complete_quarters(x, f)
complete_years_m(x, f)
complete_years_q(x, f)
|
x |
A vector of dates, or something that can be coerced into one. |
f |
A factor the same length as |
This function counts the unique year-month/year-quarters in x
and returns which elements of x
belong to a year-quarter/year with the appropriate number of year-month/year-quarters.
For example, complete_quarters
returns TRUE for an element of x
if there are three distinct year-months in the corresponding year-quarter to which this element of x
belongs.
NAs return always return NA.
If f
is given then x
is split according to f
before finding complete quarters/years in x
.
A logical vector, the same length as x
.
complete_periods
for checking completeness of non-standard calendar periods.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | # Which elements in a monthly series form complete quarters?
x <- seq(as.Date('2018-01-01'), as.Date('2019-04-01'), 'month')
x[complete_quarters(x)]
x[complete_quarters(x, c(rep('a', 10), rep('b', 6)))]
## Not run:
# Can be done manually with zoo
library(zoo)
x <- unique(as.yearmon(x))
f <- factor(as.yearqtr(x))
x[as.character(as.yearqtr(x)) %in% levels(f)[tabulate(f) == 3]]
## End(Not run)
# Which elements in a monthly series form complete years?
x[complete_years_m(x)]
# Which elements in a quarterly series form complete years?
y <- seq(as.Date('2018-01-01'), as.Date('2019-04-01'), 'quarter')
y[complete_years_q(y)]
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.