Learn R Programming

clock (version 0.7.1)

year-month-weekday-count-between: Counting: year-month-weekday

Description

This is a year-month-weekday method for the calendar_count_between() generic. It counts the number of precision units between start and end (i.e., the number of years or months).

Usage

# S3 method for clock_year_month_weekday
calendar_count_between(start, end, precision, ..., n = 1L)

Value

An integer representing the number of precision units between start and end.

Arguments

start, end

[clock_year_month_weekday]

A pair of year-month-weekday vectors. These will be recycled to their common size.

precision

[character(1)]

One of:

  • "year"

  • "quarter"

  • "month"

...

These dots are for future extensions and must be empty.

n

[positive integer(1)]

A single positive integer specifying a multiple of precision to use.

Details

Remember that year-month-weekday is not comparable when it is "day" precision or finer, so this method is only defined for "year" and "month" precision year-month-weekday objects.

"quarter" is equivalent to "month" precision with n set to n * 3L.

Examples

Run this code
# Compute the number of months between two dates
x <- year_month_weekday(2001, 2)
y <- year_month_weekday(2021, c(1, 3))

calendar_count_between(x, y, "month")

# Remember that day precision or finer year-month-weekday objects
# are not comparable, so this won't work
x <- year_month_weekday(2001, 2, 1, 1)
try(calendar_count_between(x, x, "month"))

Run the code above in your browser using DataLab