Convert numeric data into R

3

I imported a JSON table into the R and the dates are in Unix format. Example:

data <- c(1436904192, 1490717463, 1491924165)

How can I convert this entire column all at once to the date format with 14/7/15 20:03 ?

    
asked by anonymous 01.05.2017 / 21:34

1 answer

3

Simply define the scale source that the as.POSIXct function can do the conversion.

data <- c(1436904192, 1490717463, 1491924165)

as.POSIXct(data, origin="1970-01-01")
[1] "2015-07-14 17:03:12 BRT" "2017-03-28 13:11:03 BRT" "2017-04-11 12:22:45 BRT"

format(as.POSIXct(data, origin="1970-01-01"), "%d/%m/%y %H:%M:%S")
[1] "14/07/15 17:03:12" "28/03/17 13:11:03" "11/04/17 12:22:45"

Please note that I am using the timezone BRT (Brazil), the default of my operating system. And in the daylight saving time period, timezone switches from BRT to BRST. If you need to, you can set the timezone you want.

as.POSIXct(data, origin = "1970-01-01", tz = "GMT") 

[1] "2015-07-14 20:03:12 GMT" "2017-03-28 16:11:03 GMT" "2017-04-11 15:22:45 GMT"
    
01.05.2017 / 23:37