convert invalid date to a valid date like value using R

北战南征 提交于 2020-03-16 08:09:31

问题


I have a dataframe like as shown below

d1 <- c('21/01/2052 9:02','12/30/2042 9:25','10134-5-28 0:0:0','10109-12-27 0:0:0','10176-6-7 0:0:0')
d2 <- c('22/03/2052 9:22','31/10/2043 9:25','10134-6-02 0:0:0','10109-12-30 0:0:0','10176-6-9 0:0:0')
df_test <- c(d1,d2)

Input

I tried something like below using lubridate package but doesn't seem to help

mdy_hm(df_test$d1) 

This resulted in a warning message and resulted in NAs for invalid values

It's fine if invalid dates can't be processed and returns NA. if I can get output as shown below for valid dates, that is also okay

I expect my output to be like shown below (for invalid dates). If invalid dates can't be processed, then just replacing them with NA is also fine

Can you help with this?

来源:https://stackoverflow.com/questions/60202631/convert-invalid-date-to-a-valid-date-like-value-using-r

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!