add_month_fct: Add a month factor column to a data.table (by reference)

View source: R/add_month_fct.R

add_month_fctR Documentation

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

Description

Adds the month abbreviations (Jan, Feb, ...) as a factor (so to keep the annual order), with the option to define the first month (as factor level), so also hydrological years are possible (Oct, Nov, Dec, Jan, ..). Requires that input data has either a "month" or "date" column, and adds a column named "month_fct".

Usage

add_month_fct(ref_dat, first_month = 1)

Arguments

ref_dat

a data.table for which to add month_fct column

first_month

numeric, month which should be the first level (default: 1, i.e. Jan)

Value

Nothing, adds column by reference.

Examples


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

add_month_fct(dat)
str(dat)

add_month_fct(dat, 10)
summary(dat$month_fct)


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