1

I have vector of dates that looks like this (in reality the vector is much longer):

dta= data.frame(c("Mar 22, 2013", "Feb 4, 2013","Oct 3, 2016", "Apr 8, 2014", 
"Sep 6, 2013", "Jul 16, 2014"))
colnames(dta)<-c("time")

dta$time<-as.Date(dta$time, '%B %d, %Y')

Now, as I apply as.Date NA is returned for date number 2 and 4. Could someone help me to figure out what I missed? Thanks in advance!

Jannis
  • 47
  • 5

1 Answers1

1

I think it is a matter of system language. I am Italian, and if I execute your code I get NA's at 3rd, 5th, and 6th position. But if I execute:

dta= data.frame(c("Mar 22, 2013", "Feb 4, 2013","Ott 3, 2016", "Apr 8, 2014", 
              "Set 6, 2013", "Lug 16, 2014"))
colnames(dta)<-c("time")

dta$time<-as.Date(dta$time, '%B %d, %Y')

I do not get any NA's.

I solved by setting the weekdays in English:

Sys.setlocale("LC_TIME","C") # for Unix

For Windows the following should work instead (but I cannot verify):

Sys.setlocale("LC_TIME","English") # for Windows
Davide Passaretti
  • 2,741
  • 1
  • 21
  • 32