is_leap_year: Detect leap years

View source: R/utility_functions.R

is_leap_yearR Documentation

Detect leap years

Description

Given a vector or column of year values (numeric or integer), is_leap_year returns a vector of equal length of logical indicators, i.e. a vector where corresponding leap years have value TRUE, and FALSE otherwise.

Usage

is_leap_year(years)

Arguments

years

a vector or column of year values (numeric or integer)

Value

A 'logical' vector where 'TRUE' indicates a leap year.

Author(s)

Joonas Miettinen

Examples

## can be used to assign new columns easily, e.g. a dummy indicator column
df <- data.frame(yrs=c(1900,1904,2005,1995))
df$lyd <- as.integer(is_leap_year(df$yrs))

## mostly it is useful as a condition or to indicate which rows have leap years
which(is_leap_year(df$yrs)) # 2
df[is_leap_year(df$yrs),] # 2nd row


WetRobot/popEpi documentation built on Aug. 29, 2023, 3:53 a.m.