add_season_fct: Add a season factor column to a data.table (by reference)

View source: R/add_season_fct.R

add_season_fctR Documentation

Add a season factor column to a data.table (by reference)

Description

Adds the four seasons DJF, SON, MAM, JJA as a factor (so to keep the annual order), with the option to define the first season (factor level). Requires that input data has column named "month", and adds a column named "season".

Usage

add_season_fct(ref_dat, first_season = "DJF", add_n_days = FALSE)

Arguments

ref_dat

a data.table for which to add season column

first_season

character season, which should be the first level (default: "JJA")

add_n_days

logical; if T, adds the number of days in each season (of a non-leap year)

Value

Nothing, adds column by reference.

Examples


dat <- data.table::data.table(month = sample(1:12, 30, replace = TRUE))

add_season_fct(dat)
str(dat)

add_season_fct(dat, first_season = "JJA", add_n_days = TRUE)
str(dat)

mitmat/mitmatmisc documentation built on Aug. 22, 2024, 3:28 a.m.