0

Similar to the problem in Convert UNIX epoch to Date object in R, mine deals with one column of a large data table (about 250k rows). The column is a vector of many epoch times, e.g., dt$time=

c(1388839764L, 1388846894L, 1388998785L, 1389496318L, 1389525690L,
1389545726L, 1389608509L, 1389672286L, 1389696208L, 1389747353L)

How to convert such a long vector to date object? as.POSIXct(dt$time, origin='1970-01-01') has poor efficiency for such vector. While fastPOSIXct from fasttime doesn't have the origin as an argument.

Community
  • 1
  • 1
Francis
  • 6,416
  • 5
  • 24
  • 32

1 Answers1

1

Use the fasttime library and convert this vector of longs via a matrix calculation to the right origin.

Gijs
  • 10,346
  • 5
  • 27
  • 38
  • I assume you want to set a different origin. To get there, you can just do some simple calculation with the vector before feeding theses values to the `fasttime` library. What should be the first date in your vector, `'2014-01-04T13:49:24'`? – Gijs Sep 11 '15 at 08:16
  • 1
    Nope, sorry I didn't make it clear. It is because `fastPOSIXct(dt$time)` gives me `NA`; `as.POSIXct(1388839764, origin='1970-01-01')="2014-01-04 20:49:24 CST"` – Francis Sep 11 '15 at 08:30
  • Okay, I'll come back to this but I'm busy now. Sorry! – Gijs Sep 11 '15 at 08:52