0

I got this dataset for cryptocurrencies with price and volume as follows:

> head(data)
          V1   
1 1672531202 
2 1672531203 
3 1672531330 
4 1672531438 
5 1672531443 
6 1672531466 

The first column V1 is stored as 'integer' and it consists of date and time. How can I convert that column V1 into date and time column separately. Actually, I am not sure which date/time format is stored there since it is original data.

MrFlick
  • 195,160
  • 17
  • 277
  • 295
sehne
  • 1
  • 2
  • `df$datetime <- as.POSIXct(df$V1, origin = "1970-01-01", tz = "UTC")` and second part: `df$Date <- as.Date(df$datetime) df$Time <- format(df$datetime, "%T")` output: `V1 datetime Time Date 1 1672531202 2023-01-01 00:00:02 00:00:02 2023-01-01 2 1672531203 2023-01-01 00:00:03 00:00:03 2023-01-01 3 1672531330 2023-01-01 00:02:10 00:02:10 2023-01-01 4 1672531438 2023-01-01 00:03:58 00:03:58 2023-01-01 5 1672531443 2023-01-01 00:04:03 00:04:03 2023-01-01 6 1672531466 2023-01-01 00:04:26 00:04:26 2023-01-01` – TarJae Jul 20 '23 at 18:32
  • If you don't know the format you can only guess. `as.POSIXct(1672531202, origin = "1970-01-01", tz = "UTC")` gives `"2023-01-01 00:00:02 UTC"` which might be a reasonable first data point for your dateset. – jan-glx Jul 20 '23 at 18:41
  • @jan-glx Thank you for your reply. – sehne Jul 21 '23 at 09:49

0 Answers0