Evgeny Zarov
Evgeny Zarov

Reputation: 11

R can not recognize date in format

folk!

R can not recognize the next type of date: "Jun 3, 1986"

I tried it several times converting that column to factor or character.

The next examples from stackoverflow do not work and return "NA":

  1. sdate2 <- "jan151999" ndate2 <- as.Date(sdate2, "%B%d%Y"); ndate2

  2. dates <- c("May 27 1984", "July 7 2005") betterDates <- as.Date(dates, format = "%B %d %Y")

I used small letter %b and it did not work also.

  1. My version does not work as well as.Date("Jun 3, 1986", format = "%b %d, %Y")

Could you help me?

Upvotes: 0

Views: 1209

Answers (2)

Evgeny Zarov
Evgeny Zarov

Reputation: 11

And also this way works well. SOme oone suggested it but deleted afterward.

lubridate::mdy("Jun 3, 1986")

Upvotes: 0

Ronak Shah
Ronak Shah

Reputation: 388817

That is probably because your locale language is different. Change it to English and it should work.

Sys.setlocale("LC_ALL","English")
as.Date("Jun 3, 1986", format = "%b %d, %Y")
#[1] "1986-06-03"

Upvotes: 1

Related Questions