您可以将月份名称替换为月份编号,将字符串拆分为单词,并将分析日期应用于每个拆分的部分:
library(parsedate)
library(stringr)
my_date="6 May 2018 10$ party 2018-01-05 meeting"
month_list <- c("Jan","Feb","Mar","Apr","May","Jun", "Jul","Aug","Sep", "Oct","Nov","Dec")
text <-my_date
for (i in 1:12){
text <-ifelse(grepl(month_list[i], text), gsub(month_list[i], i, text), text)
}
words <- str_split(text, " ")
words[[1]][grepl("[A-Za-z]", words[[1]])] <-";"
text <- paste(words[[1]], collapse = " ")
str<- str_split(text, ";")
dates<- lapply(str,parse_date)[[1]]
dates <- dates[!is.na(dates)]