I could not find an answer to my following question via the search function:
Why does the given ifelse()
condition not work the way I intend?
I got a dataset that wrongly had an open-text field for a date and so I got a variety of ways people filled the date in. By now I really got close to something useable but my intended next step of making every mm/yy entry that was before the year 2000 a mm/19yy entry via the ifelse function does not give me a correct result:
Dates <- c("10/19", "04/2019", "O5/1992", "03/92")
ifelse(str_length(Dates)==5 & str_sub(Dates,4,5)>20, stri_sub(Dates, 4, 3) <- 19, Dates)
The result looks like this:
[1] "10/1919" "04/192019" "O5/191992" "19"
While I would want it to look like this:
1] "10/19" "04/2019" "O5/1992" "03/1992"
Any help is highy appreciated!
Aucun commentaire:
Enregistrer un commentaire