AddMonthsYM: Add a Month to a Date in YearMonth Format

Description Usage Arguments Details Value Author(s) See Also Examples

Description

The representation of year and month information in YYYYYMM format as an integer is sometimes a useful and efficient data structure. Adding a number of months to such a date is not quite catchy, however, since the date structure is to be retained. For example, 201201 - 2 [months] is expected to result in 201111 instead of 201199. AddMonthsYM does this job.

Usage

1

Arguments

x

a vector of integers, representing the dates in the format YYYYMM, to which a number of months has to be added.

n

the number of months to be added. If n is negative the months will be subtracted.

Details

All parameters will be recyled if necessary. The therefore used function mapply will display a warning, if the longer argument is not a multiple of the length of the shorter one.

Value

a vector of class integer with the same dimension as x, containing the transformed dates.

Author(s)

Andri Signorell <andri@signorell.net>, based on code by Roland Rapold

See Also

AddMonths; Date functions, like Year, Month, etc.

Examples

1
2
3
4
AddMonthsYM(201511, 5)

AddMonthsYM(c(201511, 201302), c(5, 15))
AddMonthsYM(c(201511, 201302), c(5, -4))

AndriSignorell/DescTools documentation built on April 8, 2021, 5:51 a.m.