conditional conversion from character to date for a dataframe column in r
问题 I have a dataframe I read from an excel file, like below. Date turned out to be in 5-digits format or a date string format. df = data.frame(Date = c('42195', '3/31/2016', '42198'), Value = c(123, 445, 222)) Date Value 42195 123 3/31/2016 445 42198 222 I want to clean up the column and convert everything into date format. I did the following. df %>% mutate(Date = ifelse(length(Date)==5,as.Date(Date, origin = '1899-12-30'), as.Date(Date) )) I got error like this: Error in charToDate(x) :