I wanna extract the date from a string. When I run it step by step, it works great as below
as.Date(strptime(substr("44132219721105202X",7,14),format="%Y%m%d"))
[1] "1972-11-05"
But I wanna use it in ifelse function, because I have a column strings to do that. But it doesn't work.
ifelse(nchar("44132219721105202X", type = "bytes", allowNA = FALSE, keepNA = NA)==18,as.Date(strptime(substr("44132219721105202X",7,14),format="%Y%m%d")),"44132219721105202X")