i trying convert column of dates date objects in r, can't seem desired results. these individuals have birth dates before january 1, 1970, when use as.date
r converts date 1/12/54, example, 2054-01-12. how can work around this? much.
if in 1900s, one-liner - format two-digit year @ start , slap 19 on front , convert date. again. man cool %>% stuff:
s = c("1/12/54","1/12/74") as.date(format(as.date(s,format="%d/%m/%y"), "19%y%m%d"), "%y%m%d") # [1] "1954-12-01" "1974-12-01"
if years "69" "99" 1800s, here's one-liner:
library(dplyr) # pipe operator: s %>% as.date(format="%d/%m/%y") %>% format("%y%m%d") %>% (function(d){ paste0(ifelse(d>700101,"18","19"),d) }) %>% as.date("%y%m%d") ## [1] "1954-12-01" "1874-12-01"
note not thoroughly tested might off-by-one errors or i've mixed months , days because need iso8601 compliant
Comments
Post a Comment