I get 2063 for all the dates that should be 1963. From what I gather, R starts in 1970. I would like to modify this script to take into account dates I have in the 1900s and 2000s.
Would you happen to have any suggestions? Thank you!
Thank you for that question actually! Thanks to that I've learn that the global variable LC_ALL was important for parsing month
It seems that you paste the wrong data or the wrong line of code because you specified a format of %m but you have %b
If i'm trying to replicate your line of code
per <- c("Jan-63", "Feb-63", "Mar-63", "Apr-63", "May-05", "Jun-11")
as.Date(per[1], format = "%b-%y") # return NA for me
as.Date(zoo::as.yearmon(per[1], format = "%b-%y")) # return 2063 Jan
as.Date(paste0("01-", per[1]), format = "%d-%b-%y") # return 2063-01-01
So one line return all in 1900 and the other all in 2000...
as.Date(format(as.Date(paste0("01-", per), format = "%d-%b-%y"), "19%y-%m-%d")) # 1
as.Date(paste0("01-", per), format = "%d-%b-%y") # 2
So you can't really apply the line of code you provide as example. I'm sorry to say that I haven't figure out a better solution than just reconstruct yourself the time period.
If someone comes up with a "real" solution I would be interested as well!
Sorry again
This is not common to find a parsing function that could deal with both at the same time and guess which one is 20-- and which is 19--.
By luck, lubridate has a function that supports this : parse_data_time2 and fast_strptime, which use a C parser, have a cutoff_2000 argument that allows to precise when to change to 2000 and when to stay with 1900
You can use a cutoff below 63: that way two digits number below 63 will be understand as 20th century, and all above as 19th century.