Just started learning R and I would like to convert a string of a total of 10 characters (yymmdd and some random numbers) to date format.
Example:
Numbers
1. 6010111234
2. 7012245675
3. 9201015678
4. 0404125689
Desired outcome:
Numbers Dates
1. 6010111234 1960-10-11
2. 7012245675 1970-12-24
3. 9201015678 1992-01-01
4. 0404125689 2004-04-12
I will able to do this easily in excel with the formula Dates, left and right:
DATES(LEFT(Numbers,2),RIGHT(LEFT(Numbers,4),2), RIGHT(LEFT(Numbers,6),2))
I have also tried using as.Date(substr(df$Numbers, 1,6), format=%y%m%d)
.
However, the results are not what I wanted. The results will be some 4-5 digit numbers.
Can anyone help? Thanks!