Im trying to get the date from a string such as: “ID0123122021”.
Where the first two digits are an id, then the month then the year.
So it would be equivalent to “IDnnnnmmyyyy” and the actual date would be 12-2021.
I want to extract the final date. I have tried:
as.Date("ID0123122021", format = "ID%nnnn%m%Y")
As expected it returns NA, since %n, does not exist (https://www.statology.org/r-date-format/). I also tried
as.Date("ID0123122021", format = "ID0123%m%Y")
Which does not work either and would not be particularly useful since the ID may change.
Is there any way to define a format with characters to ignore? Something like format = %iiiiii%m%Y
, Where the %i
flag would mean ignore this character when building the date?
Thanks!