以下代码返回NA
as.Date("Thr Jan 15 2015 07:06:04", format = "%a %b %d %Y %T")
已尝试按照?as.Date
## read in date info in format 'ddmmmyyyy'
## This will give NA(s) in some locales; setting the C locale
## as in the commented lines will overcome this on most systems.
## lct <- Sys.getlocale("LC_TIME"); Sys.setlocale("LC_TIME", "C")
x <- c("1jan1960", "2jan1960", "31mar1960", "30jul1960")
z <- as.Date(x, "%d%b%Y")
## Sys.setlocale("LC_TIME", lct)
答案 0 :(得分:2)
星期四的缩写是Thu
。所以,这可能会起作用
as.Date('Thu Jan 15 2015 07:06:04', format= '%a %b %d %Y %T')
# [1] "2015-01-15"
如果字符串中有typos
,请使用sub
删除工作日部分
as.Date(sub('[^ ]+ ', '', str1), format= '%b %d %Y %T')
#[1] "2015-01-15"