0
ex <- structure(list(rowid = 1:12, timestamp = structure(c(1505577931.8, 
1505577931.8, 1505577931.8, 1509206767.39, 1509206767.39, 1511019574.47, 
1511019574.47, 1511988378.544, 1511988378.544, 1511986281.239, 
1511986281.239, 1512909143.7), class = c("POSIXct", "POSIXt"), tzone = "UTC")), row.names = c(NA, 
-12L), class = c("tbl_df", "tbl", "data.frame"), .Names = c("rowid", 
"timestamp"))

With the data above, how can I print milliseconds in timestamp column?

Cœur
  • 37,241
  • 25
  • 195
  • 267
jakes
  • 1,964
  • 3
  • 18
  • 50

1 Answers1

1

We can use format to print the milliseconds

format(ex$timestamp, "%Y-%m-%d %H:%M:%OS3")
#[1] "2017-09-16 16:05:31.799" "2017-09-16 16:05:31.799" "2017-09-16 16:05:31.799"
#[4] "2017-10-28 16:06:07.390" "2017-10-28 16:06:07.390" "2017-11-18 15:39:34.470"
#[7] "2017-11-18 15:39:34.470" "2017-11-29 20:46:18.543" "2017-11-29 20:46:18.543"
#[10] "2017-11-29 20:11:21.239" "2017-11-29 20:11:21.239" "2017-12-10 12:32:23.700"
akrun
  • 874,273
  • 37
  • 540
  • 662
  • @jakes if it is a character object, it can be showed with `format` i.e. `ex %>% mutate(time_with_milli = format(timestamp, "%Y-%m-%d %H:%M:%OS3"))` – akrun Sep 25 '18 at 06:08