问题
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