4
I imported a JSON table for R and the dates are in Unix format.
Example:
data <- c(1436904192, 1490717463, 1491924165)
How can I convert this entire column at once to the date format
14/7/15 20:03
?
4
I imported a JSON table for R and the dates are in Unix format.
Example:
data <- c(1436904192, 1490717463, 1491924165)
How can I convert this entire column at once to the date format
14/7/15 20:03
?
4
Just define the source of the scale that the function as.POSIXct
can make 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"
Note that I am using Timezone BRT (Brazil), the standard of my operating system. And during daylight saving time, Timezone changes from BRT to BRST. If you need to, you can define which 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"
Browser other questions tagged r
You are not signed in. Login or sign up in order to post.