0

I use R version 3.6.1

When I run:

> as.Date('Dec 15, 2000', format = '%b %d, %Y')

I get:

[1] "2000-12-15"

On another machine with the same R version and libraries I get:

> as.Date('Dec 15, 2000', format = '%b %d, %Y')
[1] NA
zx8754
  • 52,746
  • 12
  • 114
  • 209
Oktu
  • 187
  • 1
  • 4
  • 10

1 Answers1

3

The parsing of date strings depends on the machine's language settings. If you want to work with english date strings, set the locale to (british or american) English:

> Sys.setlocale("LC_ALL", 'en_GB.UTF-8')
[1] "LC_CTYPE=en_GB.UTF-8;LC_NUMERIC=C;LC_TIME=en_GB.UTF-8;LC_COLLATE=en_GB.UTF-8;LC_MONETARY=en_GB.UTF-8;LC_MESSAGES=en_GB.UTF-8;LC_PAPER=es_ES.UTF-8;LC_NAME=C;LC_ADDRESS=C;LC_TELEPHONE=C;LC_MEASUREMENT=es_ES.UTF-8;LC_IDENTIFICATION=C"
> as.Date('Dec 15, 2000', format = '%b %d, %Y')
[1] "2000-12-15"

Edit

To be more specific, the environment variable LC_TIME is the one that determines the parsing behaviour of date strings:

Sys.setlocale("LC_TIME", 'en_GB.UTF-8')
mrhd
  • 1,036
  • 7
  • 16