是的,我发现了很多方法
但是对我来说,没有办法。
我有一个csv文件,我将其读入R
Week <- read.csv(file="week.csv", header=TRUE, sep=",", stringsAsFactors = FALSE)
我试图将StartTime和EndTime转换为datetime(例如:2019-01-04 15:13:07)
我尝试了这些方法
Week <- read.csv(file="week.csv", header=TRUE, sep=",", stringsAsFactors = FALSE)%>%
mutate(StartTime = as.POSIXct(StartTime, format = "%Y-%m-%d %H:%M:%S"))
和
Week$StartTime <- setDT(Week)[,ymd_hms(Week$StartTime)]
和
Week$StartTime <- as.POSIXct(Week$StartTime, format = "%Y-%m-%d %H:%M:%S")
但是都返回NA
我不知道还能做什么。
附加文件,希望有人可以帮助我。
https://drive.google.com/open?id=1qIOWkoVwlMu-Y6GZ_Nu0WqlcFRzyTO2v
谢谢
补充文字:
library(data.table)
Week=data.table(First=c("sat","sun","sat","sun","sat","sun","sat","sun","holiday"),
StartTime=c("2018-09-01 00:00:00","2018-09-02 00:00:00","2018-09-08 00:00:00","2018-09-09 00:00:00","2018-09-15 00:00:00","2018-09-16 00:00:00","2018-09-22 00:00:00","2018-09-23 00:00:00","2018-09-24 00:00:00"),
EndTime=c("2018-09-01 23:59:59","2018-09-02 23:59:59","2018-09-08 23:59:59","2018-09-09 23:59:59","2018-09-15 23:59:59","2018-09-16 23:59:59","2018-09-22 23:59:59","2018-09-23 23:59:59","2018-09-24 23:59:59"))