Reputation: 131
I have the data frame which has column of Date&time in the decimal format Date time is current format and expected format are like this
Date Time Expected format
1 43824.838 2019-12-27 20:06:43
2 43824.842 2019-12-27 20:12:28
3 43824.846 2019-12-27 20:18:14
4 43824.850 2019-12-27 20:24:00
5 43824.854 2019-12-27 20:29:45
6 43824.858 2019-12-27 20:35:31
7 43824.863 2019-12-27 20:42:43
8 43824.867 2019-12-27 20:48:28
With the following decimal date times:
c(43824.838, 43824.842, 43824.846, 43824.85, 43824.854, 43824.858, 43824.863, 43824.867)
Upvotes: 2
Views: 835
Reputation: 174293
In base R you can do
as_datetime <- function(x) as.POSIXct("1900-01-01") + as.difftime(x, units = "days")
dates <- c(43824.838, 43824.842, 43824.846, 43824.85,
43824.854, 43824.858, 43824.863, 43824.867)
as_datetime(dates)
#> [1] "2019-12-27 20:06:43 GMT" "2019-12-27 20:12:28 GMT" "2019-12-27 20:18:14 GMT"
#> [4] "2019-12-27 20:24:00 GMT" "2019-12-27 20:29:45 GMT" "2019-12-27 20:35:31 GMT"
#> [7] "2019-12-27 20:42:43 GMT" "2019-12-27 20:48:28 GMT"
Upvotes: 5