[R] transforming dates
Rui Barradas
ru|pb@rr@d@@ @end|ng |rom @@po@pt
Sun Nov 3 08:14:58 CET 2019
Hello,
I believe the simplest is to use package lubridate. Its functions try
several formats until either one is right or none fits the data.
x <- c('11/7/2016', '14-07-16')
lubridate::dmy(x)
#[1] "2016-07-11" "2016-07-14"
The order dmy must be the same for all vector elements, if not
y <- c('11/7/2016', '14-07-16', '2016/7/11')
lubridate::dmy(y)
#[1] "2016-07-11" "2016-07-14" NA
#Warning message:
# 1 failed to parse.
Hope this helps,
Rui Barradas
Às 02:25 de 03/11/19, reichmanj using sbcglobal.net escreveu:
> R-Help Forum
>
>
>
> I have a data set that contains a date field but the dates are in two
> formats
>
>
>
> 11/7/2016 dd/mm/yyyy
>
> 14-07-16 dd-mm-yy
>
>
>
> How would I go about correcting this problem. Should I separate the dates,
> format them , and then recombine?
>
>
>
> Sincerely
>
>
>
> Jeff Reichman
>
> (314) 457-1966
>
>
>
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
More information about the R-help
mailing list