Learn R Programming

clock (version 0.7.1)

year-month-weekday-arithmetic: Arithmetic: year-month-weekday

Description

These are year-month-weekday methods for the arithmetic generics.

  • add_years()

  • add_quarters()

  • add_months()

Notably, you cannot add days to a year-month-weekday. For day-based arithmetic, first convert to a time point with as_naive_time() or as_sys_time().

Usage

# S3 method for clock_year_month_weekday
add_years(x, n, ...)

# S3 method for clock_year_month_weekday add_quarters(x, n, ...)

# S3 method for clock_year_month_weekday add_months(x, n, ...)

Value

x after performing the arithmetic.

Arguments

x

[clock_year_month_weekday]

A year-month-weekday vector.

n

[integer / clock_duration]

An integer vector to be converted to a duration, or a duration corresponding to the arithmetic function being used. This corresponds to the number of duration units to add. n may be negative to subtract units of duration.

...

These dots are for future extensions and must be empty.

Details

Adding a single quarter with add_quarters() is equivalent to adding 3 months.

x and n are recycled against each other using tidyverse recycling rules.

Examples

Run this code
# 2nd Friday in January, 2019
x <- year_month_weekday(2019, 1, clock_weekdays$friday, 2)
x

add_months(x, 1:5)

# These don't necessarily correspond to the same day of the month
as_year_month_day(add_months(x, 1:5))

Run the code above in your browser using DataLab