f.monthly: Create a Monthly Frequency

View source: R/frequency.R

f.monthlyR Documentation

Create a Monthly Frequency

Description

Use this function to create a frequency for time-series data that occurs monthly.

Usage

f.monthly(year, month)

Arguments

year

An integer representing the year of the observation.

month

An integer representing the month of the observation (It should be between 1 to 12).

Details

In order to use the as.frequency function for this type of frequency, you need the following information:

  • Character Format "#m#" (first # is the year, second # is the month (1 to 12); e.g., 2010m8 or 2010m12. Note that 2000m0 or 2000m13 are invalid.

  • Class Id "m"

Value

An object of class ldtf which is also a list with the following members:

class

Determines the class of this frequency.

year

Determines the year.

month

Determines the month.

Examples


m0 <- f.monthly(2020, 2)
#     this is a monthly frequency that refers to the second month of the year 2020.

m0_value_str <-  as.character(m0) # this will be '2020M2'.
m0_class_str <- get.class.id(m0) # this will be 'm'.

m_new <- as.frequency("2021m3", "m")
#     this is a monthly frequency that refers to the third month of the year 2021.

# Don't make the following mistakes:

m_invalid <- try(f.monthly(2020, 0))
m_invalid <- try(f.monthly(2020, 5))
m_invalid <- try(as.frequency("2021m0", "m"))
m_invalid <- try(as.frequency("2021m13", "m"))
m_invalid <- try(as.frequency("2021", "m"))



tdata documentation built on Nov. 7, 2023, 5:07 p.m.