0

I have dates formatted as character strings following the format of this example:

"Wednesday 18 May 2016"

Is there a way to convert it into date directly, maybe with as.Date(mystring,someformat) ?

moodymudskipper
  • 46,417
  • 11
  • 121
  • 167

1 Answers1

2

We can remove the Wednesday followed by space with sub and convert to 'Date'

as.Date(sub("^\\S+\\s+", "", str1), "%d %b %Y")
#[1] "2016-05-18"

If we are using lubridate, just use dmy

library(lubridate)
dmy(str1)
#[1] "2016-05-18 UTC"

data

str1 <- "Wednesday 18 May 2016"
akrun
  • 874,273
  • 37
  • 540
  • 662