我有一个sql查询的日期作为一个因素,我想使它成为一个POSIXct
f<- as.factor("01/03/2014 20:59:30")
f
class(f)
po<-as.POSIXct(f)
po
结果
> f<- as.factor("01/03/2014 20:59:30")
> f
[1] 01/03/2014 20:59:30
Levels: 01/03/2014 20:59:30
> class(f)
[1] "factor"
> po<-as.POSIXct(f)
> po
[1] "0001-03-20 LMT"
你可以看到“0001-03-20 LMT”不正确 . 你知道怎么把这个因子转换成POSIXct吗?
谢谢
2 回答
您可以使用
lubridate
使这更简单您只需要指定格式,因为您的日期/时间字符串是非常非标准甚至模糊的格式:
请参阅http://stat.ethz.ch/R-manual/R-devel/library/base/html/as.POSIXlt.html上的文档 .