Reputation: 2233
I have data from a csv file that when imported to R looks like this ( last row value of DisChargeDate field is wrong):
VisitDate VisitHour DisChargeDate DisChargeHour
01/12/2012 14:24:33 01/13/2012 00:34:09
01/12/2012 14:29:07 01/12/2012 18:40:01
01/12/2012 19:20:39 01/12/2012 20:56:11
01/12/2012 19:43:40 1/13/2012 01:53:50
How can I fix this issue so I'll be able to change the variable for date format like in the code below that works file If I remove the last row:
library(lubridate)
df$visitDateTime<-with(df, dmy(DisChargeDate ) + hms(DisChargeHour))
Upvotes: 0
Views: 39
Reputation: 3514
You just need to replace dmy()
by mdy()
e.g.:
library(lubridate)
df$visitDateTime<-with(df, mdy(DisChargeDate ) + hms(DisChargeHour))
VisitDate VisitHour DisChargeDate DisChargeHour visitDateTime
1 01/12/2012 14:24:33 01/13/2012 00:34:09 2012-01-13 00:34:09
2 01/12/2012 14:29:07 01/12/2012 18:40:01 2012-01-12 18:40:01
3 01/12/2012 19:20:39 01/12/2012 20:56:11 2012-01-12 20:56:11
4 01/12/2012 19:43:40 1/13/2012 01:53:50 2012-01-13 01:53:50
Upvotes: 1