dmy: Date parse

View source: R/utils2.R

dmyR Documentation

Date parse

Description

Parses day, month, and year columns to the standard date format.

Usage

dmy(d, m, y, origin = c(1, 1, 1900))

Arguments

d, m, y

day, month, year as single integers or vectors

origin

a vector of length three giving the origins for d, m, and y, respectively; see details

Details

For two-digit years, the origin year should be specified; otherwise, the default of 1900 will be used. For NA year, month, or day, origin is used for defaults, i.e., origin = c(15, 6, 2000) will convert missing days to day 15, missing months to June, and missing years to 2000.

Value

A vector of Date-formatted strings.

Examples

dmy(25, 7, 13)
dmy(25, 7, 2013)
dmy(NA, NA, 2000:2009)

set.seed(1)
dd <- data.frame(
  id = 1:10,
  day = sample(1:31, 10),
  month = sample(1:12, 10),
  year = sample(1000:2500, 10)
)

cbind(dd, dt = with(dd, dmy(day, month, year)))


## NAs will be filled with corresponding values of origin
dd[, -1] <- lapply(dd[, -1], function(x) {x[sample(nrow(dd), 5)] <- NA; x})
cbind(dd, dt = with(dd, dmy(day, month, year, origin = c(15, 6, 2000))))


raredd/rawr documentation built on May 9, 2024, 6:14 p.m.