Lubridate find invalid dates

When I run this command to check if the date columns are in the correct yyyy-mm-dd format

df1 <- df %>% mutate(date_created = lubridate::ymd(df$date_created) )

I get the following message 2117 failed to parse- which is great ( there are over 200,000 rows ) as some will be wrong BUT how do I know which ones have failed ?


if they failed to parse, then they will appear as NA at those locations in the date_created field you made.
p.s. when using the tidyverse you should avoid using $ selection unless you cannot achieve some effect without it, in your example if seems redundant at best, given that mutate knows it operates on df from the first pipe you make.

Thanks. but how do I then ink the original dataframe and show what the dates entered were

you can preserve your original data, by not overwriting it. perhaps

df1 <- df %>% mutate(date_created_parsed =  lubridate::ymd(date_created))

Then you will have in df1 both parsed and the original date created fields

This topic was automatically closed 42 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.