Learn R Programming

tdata (version 0.3.0)

f.weekly: Create a Weekly Frequency

Description

Use this function to create a frequency for time-series data that occurs weekly. The first day of the week is used as the reference.

Usage

f.weekly(date)

Value

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

class

The class of this frequency.

year

The year.

month

The month.

day

The day.

Arguments

date

The date, which can be a list with year, month, and day elements. It can also be an integer array with 3 elements for year, month, and day respectively, or an object that can be used as an argument for the base::as.Date function. This date determines the start of the week.

Details

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

  • Character Format The first day of the week in "YYYYMMDD" format.

  • Class Id "w"

Examples

Run this code

w0 <- f.weekly(c(2023, 1, 2)) # This is 2/1/2023, which is Monday.
#    The next observation belongs to 9/1/2023.

w0_value_str <-  as.character(w0) # this will be '20230102'.
w0_class_str <- get.class.id(w0) # this will be 'w'.

w_new <- as.frequency("20230109", "w") # This is 9/1/2023.

# Don't use invalid or unsupported dates:
# \donttest{
w_invalid <- try(as.frequency("1399109", "w")) # this is a too old date and unsupported
w_invalid <- try(as.frequency("20230132", "w")) # invalid day in month
w_invalid <- try(as.frequency("20231331", "w")) # invalid month
# }

Run the code above in your browser using DataLab