Naomi Peer
Naomi Peer

Reputation: 367

Very simple : as.Date error with August

I'm trying to use as.Date with some data, but I encounter NAs with specific months. I created a data.frame named Fake to test it, and it gave me the same error : it works with September but not with August.

Fake <- c("Sep 12 2014", "Aug 12 2014")
as.Date(Fake, format ="%b %d %Y")

This is what I get:

> as.Date(Fake, format ="%b %d %Y")
[1] "2014-09-12" NA  

I need to use June data also but it doesn't work, even if July data does. Anyone can help?

Upvotes: 3

Views: 286

Answers (2)

leakciM
leakciM

Reputation: 82

You should open try opening your terminal and run the following command in the prompt :

defaults write org.R-project.R force.LANG en_US.UTF-8

Then relaunch R or RStudio and try running your code again. Everything should work. If you need further information you can check this blog :

http://mito.air-nifty.com/mitoakiyoshiblog/2010/03/how-to-change-l.html

Upvotes: 1

bgoldst
bgoldst

Reputation: 35314

The issue is that you have a French locale, which uses different month and day names and abbreviations. You can change to the English locale by running:

Sys.setlocale('LC_ALL','en_CA.utf-8');

Edit: You might also/instead have to run this (I've found this to be necessary in RStudio):

Sys.setlocale('LC_ALL','English');

References that might be useful to people:

Upvotes: 4

Related Questions