dmy | R Documentation |
Parses day, month, and year columns to the standard date format.
dmy(d, m, y, origin = c(1, 1, 1900))
d , m , y |
day, month, year as single integers or vectors |
origin |
a vector of length three giving the origins for |
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.
A vector of Date
-formatted strings.
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))))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.