How do I convert a character field to date/time format in R?

r
data_science

#1

How do I convert a character field to date/time format in R?


#2

use strptime

https://stat.ethz.ch/R-manual/R-devel/library/base/html/strptime.html

or use package lubridate

http://cran.r-project.org/web/packages/lubridate/vignettes/lubridate.html

library(lubridate)
ymd(“20110604”)

[1] “2011-06-04 UTC”

mdy(“06-04-2011”)

[1] “2011-06-04 UTC”

dmy(“04/06/2011”)

[1] “2011-06-04 UTC”