Package 'ymq'

Title: Year Months and Quarters
Description: Operators to manipulate integers representing year months in the form YYYYMM, and year quarters in the form YYYYQQ.
Authors: Steve Martin [aut, cre, cph]
Maintainer: Steve Martin <[email protected]>
License: MIT + file LICENSE
Version: 0.1.0
Built: 2024-09-12 02:42:44 UTC
Source: https://github.com/marberts/ymq

Help Index


Year Months and Quarters

Description

Operators to manipulate integers representing year months in the form YYYYMM, and year quarters in the form YYYYQQ.

Author(s)

Maintainer: Steve Martin [email protected]

See Also

https://github.com/marberts/yqm


Convert YYYYMM to YYYYQQ.

Description

Use m2q() to turn YYYYMM into YYYYQQ and q2m() to turn YYYYQQ into the first YYYYMM.

Usage

m2q(x)
q2m(x)

Arguments

x

An integer vector of year months of the form YYYYMM, or year quarters of the form YYYYQQ.

Value

For q2m(), an integer vector of the form YYYYMM; for mq2(), an integer vector of the form YYYYQQ.

Examples

m2q(202103)
q2m(202103)

# Represent as the third month of the quarter
q2m(202103) %+m% 2L

# Represent as YYYYMMDD
q2m(202103) * 100L + 1L

Number of integer digits

Description

Count the number of integer digits in a number.

Usage

digits(x)

Arguments

x

A numeric vector.

Value

An integer vector giving the number of integer digits in x.

Examples

digits(100)
digits(100.1)
digits(-0.1)

Infix operators to work with integers representing year months (YYYYMM) and year quarters (YYYYQQ).

Description

  • %+m% and %-m% add/subtract months for year months.

  • %m-m% finds the difference (in months) between year months.

  • %m:m% generates a sequence of year months.

  • Switching 'm' for 'q' does the same for year quarters.

Usage

e1 %+m% e2
e1 %-m% e2
e1 %m-m% e2
e1 %m:m% e2

e1 %+q% e2
e1 %-q% e2
e1 %q-q% e2
e1 %q:q% e2

Arguments

e1, e2

An integer vector of year months of the form YYYYMM, or year quarters of the form YYYYQQ.

Value

An integer vector of the form YYYYMM, or YYYYQQ.

Examples

# Add or subtract months/quarters
202101 %+m% 13
202101 %-m% 13
202101 %+q% 5
202101 %-q% 5

# Find the difference
202101 %m-m% 202202
202202 %q-q% 202101

# Make a sequence
202101 %m:m% 202202
202101 %q:q% 202202