我有以下包含日期/时间的字符向量。我想将它们转换为日期格式,我尝试了以下方法:as.Date()
和as.POSIXct()
time <- c("Oct 01,2015 15:38:31 ", "Oct 05,2015 11:07:14", "Oct 11,2015 14:15:51 ", "Oct 11,2015 14:19:53 ", "Oct 12,2015 11:23:28", "Oct 19,2015 16:32:51 ")
#as.Date() is skipping the time part
time_1<-as.Date(time,"%b %d,%Y %H:%M:%S")
time_1
[1] "2015-10-01" "2015-10-05" "2015-10-11" "2015-10-11" "2015-10-12" "2015-10-19"
#POSIXct is showing an error
time_2<-as.POSIXlt(time,"%b %d,%Y %H:%M:%S")
该as.Date()
函数正在跳过时间部分并POSIX
引发错误(这很明显)。
如何将上述字符串转换为正确的日期+时间格式?