0

If I have a vector of unix timestamps, for example

> head(debug$time)
[1] 1.473639e+18 1.473639e+18 1.473639e+18 1.473639e+18 1.473640e+18
[6] 1.473640e+18

How can I use it as a Date vector in order to form a ts or xts object ? I need this in order to parameterise and use the bfast library docs

I tired to do the following (tz=CEST is not recognised btw):

t_ <- as.POSIXct(as.numeric(debug$time), origin = '1970-01-01')

Could you please advise on this one ?

nskalis
  • 2,232
  • 8
  • 30
  • 49

1 Answers1

2

Use this for a way around the CEST problem, but all you need to do is:

vals <- c(1.473639e+18, 1.473639e+18, 1.473639e+18, 1.473639e+18, 1.473640e+18, 1.473640e+18)
as.POSIXct(vals/1000000000, origin="1970-01-01 00:00:00")
## [1] "2016-09-11 20:10:00 EDT" "2016-09-11 20:10:00 EDT" "2016-09-11 20:10:00 EDT" "2016-09-11 20:10:00 EDT" "2016-09-11 20:26:40 EDT"
## [6] "2016-09-11 20:26:40 EDT"

To make the date/time conversion work.

UPDATE

Looks like you can also do:

as.POSIXct(vals/1e9, origin="1970-01-01 00:00:00", tz="Etc/GMT+2")

to get your CEST working as well (from what I read, that's an equivalent time zone, but I don't live there or work with data from there so cannot validate that statement). Also using the scientific notation for Rich's sake :-)

Community
  • 1
  • 1
hrbrmstr
  • 77,368
  • 11
  • 139
  • 205