I have a character vector
x=c("Thu Jan 30 2020")
when I use function as.Date in base
package as follows, it returns NA.
as.Date(x,format="%a %b %d %Y")
What am I doing wrong?
I have a character vector
x=c("Thu Jan 30 2020")
when I use function as.Date in base
package as follows, it returns NA.
as.Date(x,format="%a %b %d %Y")
What am I doing wrong?
A hard-coding workaround
s <- unlist(strsplit(x, " "))[c(4, 2, 3)]
as.Date(paste0(
replace(
s,
2,
sprintf("%02d", match(s[2], month.abb))
),
collapse = "-"
))