How to get origin from POSIXct object

99封情书 提交于 2019-12-10 23:31:56

问题


I have a function like so:

foo = function(time_in){
    # code here that changes POSIXct to numeric
    time_out = as.POSIXct(time_in, origin = '1970-01-01')
}

where the user enters time_in as a POSIXct object. I use this parameter in a linear model (lm()) which spits my value back out as a numeric. Finally, I want to convert it back to a POSIXct object for my user. The problem is, as.POSIXct() requires an origin which is typically Jan 1, 1970 UTC. But what if my user is working off a different origin? How can I extract the origin from time_in to use it as an argument for time_out?

I have looked for documentation on how to get the origin, but str(time_in) and attributes(time_in) don't give me anything and I haven't found much else. Since this will be in a package, I'd like to stick with base R functions to limit the number of dependencies needed.

来源:https://stackoverflow.com/questions/37690722/how-to-get-origin-from-posixct-object

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