complete_quarters: Complete quarters / years

Description Usage Arguments Details Value See Also Examples

Description

Identify which elements in a vector of dates correspond to complete quarter/years.

Usage

1
2
3
4
5

Arguments

x

A vector of dates, or something that can be coerced into one.

f

A factor the same length as x, or an atomic vector to be turned into a factor, that is used to group x.

Details

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.

Value

A logical vector, the same length as x.

See Also

complete_periods for checking completeness of non-standard calendar periods.

Examples

 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)]

ppd-dpp/calpr documentation built on June 25, 2020, 12:09 a.m.