Getting the month from different Date formats in R

nasifffors

I am trying this code and figuring out why in the second instance I am not getting the month of the Date.

event_text <- c("7-May","Aug-89")

month(strptime(event_text[1], format = "%d-%b"))

5 #fine

month(strptime(event_text[2], format = "%b-%y"))

NA #not fine

Jilber Urbina

We can use month.abb and some regex:

> months <- gsub("\\d+|\\-", "", event_text)
> which(month.abb %in% months)
[1] 5 8

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related