Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我将日期格式化为遵循此示例格式的字符串:
“2016 年 5 月 18 日,星期三”
有没有办法直接将其转换为日期,也许是 as.Date(mystring,someformat) ?
我们可以删除Wednesday后面的空格sub并转换为“日期”
Wednesday
sub
as.Date(sub("^\\S+\\s+", "", str1), "%d %b %Y") #[1] "2016-05-18"
如果我们正在使用lubridate,只需使用dmy
lubridate
dmy
library(lubridate) dmy(str1) #[1] "2016-05-18 UTC"
str1 <- "Wednesday 18 May 2016"