我有一个连接,它带来来自slq的数据,格式为datetime。我也需要保持tre时间。
head(llamMitUadm$responseTime)
[1] "2014-10-07 08:00:33.780" "2014-10-07 08:01:17.813" "2014-10-07 08:01:19.450"
[4] "2014-10-07 08:01:34.773" "2014-10-07 08:01:54.950" "2014-10-07 08:02:08.607"
> class(llamMitUadm$responseTime)
[1] "character"
然后我将其转换为datetime:
llamMitUadm$responseTime1<-strptime(llamMitUadm$responseTime, format="%Y-%m-%d %H:%M:%S")
> class(llamMitUadm$responseTime1)
[1] "POSIXlt" "POSIXt"
> head(llamMitUadm$responseTime1)
[1] "2014-10-07 08:00:33 ART" "2014-10-07 08:01:17 ART" "2014-10-07 08:01:19 ART"
[4] "2014-10-07 08:01:34 ART" "2014-10-07 08:01:54 ART" "2014-10-07 08:02:08 ART"
我需要进行sql查询,我收到以下错误:
Error in sqliteSendQuery(conn, statement, bind.data) :
RAW() can only be applied to a 'raw', not a 'double'
我读到这与POSIXt格式有关。如何保持datime并能够执行查询?
Altought我知道与查询无关,我添加了一个可重现的例子:
data<-data.frame(date=c("2014-10-07 08:00:33.780","2014-10-07 08:01:17.813","2014-10-07 08:01:19.450"))
> class(data$date)
[1] "factor"
data$date<-as.character(data$date)
> class(data$date)
[1] "character"
data$date1<-strptime(data$date, format="%Y-%m-%d %H:%M:%S")
> class(data$date1)
[1] "POSIXlt" "POSIXt"
library(sqldf)
> sqldf("Select * from data")
Error in sqliteSendQuery(conn, statement, bind.data) :
RAW() can only be applied to a 'raw', not a 'double'
答案 0 :(得分:2)
POSIXlt是一个列表,因此无法存储在数据框中。我解决了它:
as.POSIXct(llamMitUadm$responseTime)