adam.888 adam.888 - 1 year ago 68
R Question

R converting a character to a date

I have a character string of type DEC 2016 and I want to convert it into a date.

I tried:

dates1 <- c("DEC 2016", "FEB 2017", "NOV 2018")

dates2 <- as.Date(dates1,format="%b %Y")

but this did not work.

Thank you for your help.

Answer Source
dates1 <- c("DEC 2016", "FEB 2017", "NOV 2018")

dates2 <- as.Date(as.yearmon(dates1))

[1] "2016-12-01" "2017-02-01" "2018-11-01"
[1] "Date"

You should really do some Googling.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download