1 year ago
#42495
Jonas Lindeløv
How to write POSIXct with milliseconds using vroom_write()?
How can I write POSIXct
columns with milliseconds using vroom::vroom_write()
?
I can use format()
before saving to "render" the time as character (see below), but I wonder if there's a neater way, e.g., by setting some option?
# Example data
df = data.frame(time = Sys.time() + runif(5, 0, 10^6))
# Convert POSIXct cols
POSIXct_cols = sapply(df, \(x) "POSIXct" %in% class(x))
df[POSIXct_cols] = lapply(df[POSIXct_cols], \(x) format(x, "%Y-%m-%d %H:%M:%OS3")))
# Save
vroom::vroom_write(df, "df.csv")
formatting
posixct
vroom
0 Answers
Your Answer