Skip to contents

When the dimension is defined as a date type, using this function we can select the week level and its attributes to include in it: week and year_week.

Usage

select_week_level(td, include_all, exclude_all, week, year_week)

# S3 method for when
select_week_level(
  td,
  include_all = FALSE,
  exclude_all = FALSE,
  week = NULL,
  year_week = NULL
)

Arguments

td

A when object.

include_all

A boolean, include all fields of the level.

exclude_all

A boolean, exclude all fields of the level.

week

A boolean, include the week number.

year_week

A boolean, include the year-week combination.

Value

A when object.

Details

The include_all and exclude_all parameters allow us to include or exclude all attributes, and then specifically exclude or include the ones we need.

For the first and last days of the year, the year associated with the week may be different from the year of the date, depending on the date type selected.

The week number associated with each date depends on the type of date dimension selected: standard ('date'), ISO 8601 ('iso') or epidemiological ('epi').

The standard week numbers blocks of 7 days beginning on January 1. The last week of the year can be less than 7 days long.

The ISO 8601 week numbers blocks of 7 days from Monday to Sunday. The first and last week of the year can contain days from the previous or next year.

The epidemiological week is like ISO 8601 only that it considers that the week begins on Sunday.

Examples


td <- when() |>
  select_week_level(year_week = FALSE)