I have a data frame where date is stored as a double
e.g., 1993.09 1993.10 1993.11 1993.12
I want to convert this into a date format '%Y %m %d'
(with days always 1
).
As far as I understand, as.Date()
wants a string input. However, for some reason when I convert my dates into string sapply(dates, as.character)
the zeros after ones disappear, effectively converting October to January, resulting into two Januaries per year.
dates
1993.07 1993.08 1993.09 1993.10 1993.11 1993.12
sapply(dates, as.character)
sub("[.]", " ", dates)
"1993 07" "1993 08" "1993 09" "1993 1" "1993 11" "1993 12"
Is there a more straightforward way of converting the dates? Or where do I mess up?
dput:
c(1993.01, 1993.02, 1993.03, 1993.04, 1993.05, 1993.06, 1993.07,
1993.08, 1993.09, 1993.1, 1993.11, 1993.12)