Reputation: 47300
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) ?
Upvotes: 0
Views: 146
Reputation: 886948
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"
str1 <- "Wednesday 18 May 2016"
Upvotes: 2