0

My data set contains Unix timestamp column, that I need to convert in UTC. I used as.POSIXct to convert the column to UTC, but throws an error like

Error in as.POSIXct.numeric(df$timestamp) : 'origin' must be supplied

I added the origin as as.POSIXct(df$timestamp, origin="1970-01-01", tz="UTC") but still getting the same error :(

I am bit new in R and kind of lost! Could someone show me some path?

reptile
  • 3
  • 2
  • Please provide some sample data e.g. with `dput(head(df$timestamp))` – shs Jun 02 '20 at 20:11
  • Can you show the format of the 'timestamp' – akrun Jun 02 '20 at 20:15
  • .. and the code you use that is generating it. (If you truly only reference it as `as.POSIXct(df$timestamp, origin="1970-01-01")` in this one place and never reference it elsewhere, then ... something is wrong.) Please make this question *reproducible*. This includes sample code you've attempted (including listing non-base R packages, and any errors/warnings received), sample *unambiguous* data (e.g., `dput(head(x))` or `data.frame(x=...,y=...)`), and intended output. Refs: https://stackoverflow.com/q/5963269, [mcve], and https://stackoverflow.com/tags/r/info. – r2evans Jun 02 '20 at 20:16

1 Answers1

0

I am not sure about your data but Anytime library might be an help!

library(anytime)

anytime(value) or anytime(table$column)

Then you can use as.POSIXct() (only if it the problem is still there). Probably this is not a simplified solution but worked for me! You can follow experts advice on this.

NOTE: You can also use anydate(value) from the same library to get the date only.

temp
  • 82
  • 1
  • 10