[英]Converting non-standard dates in r
My date information is a string in the following format: 3/12/1956 0:00:00 我的日期信息是以下格式的字符串:1/12/3956 0:00:00
I have tried converting it using DOB<-as.Date(DOB, "%d/%m/%y %H:%M:%S") 我尝试使用DOB <-as.Date(DOB,“%d /%m /%y%H:%M:%S”)进行转换
I am trying to convert it for the purpose of then applying the age_calc function in eeptools package. 我正在尝试将其转换,然后在eeptools包中应用age_calc函数。
Is there some other way to change a non standard format into a date. 还有其他方法可以将非标准格式更改为日期。 Damn Aussie dates!
该死的澳大利亚约会!
You can try lubridate
as an alternative 您可以尝试使用
lubridate
library(lubridate)
DOB <- '3/12/1956 0:00:00'
mdy_hms(DOB)
#[1] "1956-03-12 UTC"
It can also take multiple
formats 它也可以采用
multiple
格式
DOB <- c('3/12/1956 0:00:00', '3.12/1956 0.00/00')
mdy_hms(DOB)
#[1] "1956-03-12 UTC" "1956-03-12 UTC"
Or as @Richard Scriven commented, 或就像@Richard Scriven所说的那样,
as.Date(DOB, "%d/%m/%Y %H:%M:%S")
#[1] "1956-12-03"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.