如果要将两种类型的字符串直接转换为日期,则可以使用包中的dmy()函数lubridate。
library(lubridate)
date.vector <- c("01-01-2016", "02/01/2016", "03-01-2016", "04-01-2016")
dmy(date.vector)
# > dmy(date.vector)
# [1] "2016-01-01" "2016-01-02" "2016-01-03" "2016-01-04"
Run Code Online (Sandbox Code Playgroud)