Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Very simple : as.Date error with August

Tags:

r

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?

like image 586
Naomi Peer Avatar asked Feb 22 '26 16:02

Naomi Peer


1 Answers

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:

  • How to change the locale of R in RStudio?
  • The R console is in my native language, how can I set R to English?
like image 79
bgoldst Avatar answered Feb 25 '26 05:02

bgoldst



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!