Lubridate problems with NA

Why am I getting NA when parsing this date?

 library(lubridate)
 d2 <- "2015-Mar-07"
 ymd(d2)

 > NA

I'm not getting failures with some other examples. Is it because Mar is in Spanish? How can I force it to parse the date?

My locale settings:

> readr::locale()
<locale>
Numbers:  123,456.78
Formats:  %AD / %AT
Timezone: UTC
Encoding: UTF-8
<date_names>
Days:   Sunday (Sun), Monday (Mon), Tuesday (Tue), Wednesday (Wed), 
Thursday (Thu), Friday (Fri), Saturday (Sat)
Months: January (Jan), February (Feb), March (Mar), April (Apr), May 
(May), June (Jun), July (Jul), August (Aug),
    September (Sep), October (Oct), November (Nov), December (Dec)
AM/PM:  AM/PM

Thanks

Upvotes: 0

Views: 688

Answers (1)

Francesco Grossetti
Francesco Grossetti

Reputation: 1595

UPDATE

Everything works fine here. Could you check the lubridate version you have installed? I have v1.7.4 on R 3.6.3.

library(lubridate)
d2 <- "2015-Mar-07"
> ymd(d2)
[1] "2015-03-07"

Alternatively, you can use base R and force the format:

d2 <- "2015-Mar-07"
d2new = as.Date(d2, format = "%Y-%b-%d")
> d2new
[1] "2015-03-07"

Upvotes: 1

Related Questions