2

I am new to R, and having trouble converting my characters to aDATE format.

I have looked at Converting character into a Date format [duplicate] and tried using the suggestions there, but I keep getting NA's instead.

library(zoo)
t<-as.yearmon(select.oneseries$SERIES_DT)
str(select.oneseries$SERIES_DT)
str(t)

When I execute the code, I get the following results

chr [1:18] "01OCT2014" "01JAN2015" "01APR2015" "01JUL2015" "01OCT2015" ...
'yearmon' num [1:18] NA NA NA NA ... 

my expectation is t to be populated with actual DATE formats instead of NAs.

Any help would be appreciated.

deepseefan
  • 3,701
  • 3
  • 18
  • 31
Lonewolf
  • 197
  • 2
  • 13

1 Answers1

3

Use lubridate package. Then you deffine order of day, month and year in string.

library(lubridate)

dmy('01OCT2014')
lypskee
  • 342
  • 1
  • 11
  • thanks! just a quick question, what is the next steps after defining it? Should it be as.Date(select.oneseries$SERIES_DT,format="dmy")? – Lonewolf Aug 13 '19 at 14:47