0

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.

adam.888
  • 7,686
  • 17
  • 70
  • 105

1 Answers1

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

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

dates2
[1] "2016-12-01" "2017-02-01" "2018-11-01"
class(dates2)
[1] "Date"

You should really do some Googling.

lao_zhang
  • 178
  • 8