Integer to POSIXlt

百般思念 提交于 2019-12-02 04:11:12

There is an as.POSIXct.numeric method:

 > methods(as.POSIXct)
[1] as.POSIXct.date    as.POSIXct.Date    as.POSIXct.dates   as.POSIXct.default
[5] as.POSIXct.numeric as.POSIXct.POSIXlt

It uses numeric input as the number of seconds offset from the origin.

> as.POSIXct(1107151300, origin = '2011-07-15 13:00:00')
[1] "2046-08-14 19:01:40 PDT"
> as.POSIXct('1107151300', format = '%y%m%d%H%M', 
                          origin = '2011-07-15 13:00:00')
[1] "2011-07-15 13:00:00 PDT"

So, yes, you do need to use as.character.

Try removing the format spec (I believe it is only needed for character input):

zz <- as.POSIXct(Date.Time, origin = '2011-07-15 13:00:00')

It will work if you supply Date.Time as time in actual seconds from '2011-07-15 13:00:00' with the correct time zone

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!