Reputation: 2825
I'm having trouble changing date format in R. I have a vector "StartDate"
with dates and time for instance in the format:
01Feb1991 00:00
I did:
as.POSIXct(as.character(bio$StartDate), format = "%d/%m/%Y %H:%M")
...but I got NA
s as a result. Would there be a different way to change the vector into date format?
Upvotes: 0
Views: 93
Reputation: 56935
The format you provide has to match your string. In your case, that's '%d%b%Y %H:%M' (you don't have slashes between day, month and year, and your month is the abbreviated name, not the number).
as.POSIXct('01Feb1991 00:00', format='%d%b%Y %H:%M')
See ?strptime
(mentioned in ?as.POSIXct
) for various tokens you can use for dates.
Upvotes: 2