R: Converting numeric timestamp to POSIXct object returns NA

1.7k views Asked by At

I know this is a common problem, but none of the many other questions I saw fixed this for me. I'm trying to convert numeric timestamps to POSIXct, but no matter what I do, it gives me NA. For example:

as.POSIXct(20090319043255, format="%Y%m%d%H%M%S", origin="1970-01-01")

I've tried just about every variation on the formatting I can think of: inserting spaces, changing the origin format, excluding the origin (which just gives me the "origin must be supplied" error), everything. I'm stumped. Is there something stupid I'm missing?

Before you ask, yes, I've checked the locale. I'm in the United States.

1

There are 1 answers

0
Lovetoken On

I recommend using the lubridate package. Try running the below code.

> library(lubridate)
> ymd_hms("20090319043255")
[1] "2009-03-19 04:32:55 UTC"