Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个带有时间戳的数据框,如下所示:
2020-06-28T16:45:04.3602059+03:00
我随时使用包功能随时转换其格式:
df <- df %>% dplyr::mutate( timestamp = anytime::anytime(timestamp))
所以在那个时间戳之后看起来像这样:
2020-06-28 16:45:04
但我在这里失去了几毫秒。在这种特定的初始格式的情况下,我如何在保持毫秒的情况下进行转换?
毫秒保留在数据中,但POSIXct该类有一个显示方法,可以截断到秒。使用包中的second()函数lubridate,我们可以提取 date.time 的秒部分,POSIXct并看到毫秒仍然存在:
POSIXct
second()
lubridate
library(anytime) library(lubridate) dt1 = anytime("2020-06-28T16:45:04.3602059+03:00") second(dt1) 4.360205