[color=rgba(0, 0, 0, 0.75)]
我有一个包含不完整日期时间变量的数据框。数据的间隔是0.5秒。我想找出丢失的时间点并为每个丢失的时间点插入一条记录。例如,数据如下所示:
[color=rgb(119, 120, 136) !important]
df <- structure(list(time = structure(c(1652182189, 1652182189, 1652182190, 1652182191
[color=rgb(119, 120, 136) !important]
), class = c("POSIXct", "POSIXt"), tzone = ""), positionx = 3:6),
[color=rgb(119, 120, 136) !important]
row.names = c(NA, -4L), class = "data.frame")
我尝试用 pad() 解决它。
[color=rgb(119, 120, 136) !important]
pad(df, interval = " .5 sec")
[color=rgb(119, 120, 136) !important]
但是,由于pad()的间隔的最小单位是秒,所以会出现如下错误。
[color=rgb(119, 120, 136) !important]
Error: interval is not valid.
[color=rgb(119, 120, 136) !important]
我想填充数据框如下。如何解决这个问题呢?请给我一些建议~
[color=rgb(119, 120, 136) !important]
time positionx
[color=rgb(119, 120, 136) !important]
<dttm> <int>
[color=rgb(119, 120, 136) !important]
1 2022-05-10 19:29:49 3
[color=rgb(119, 120, 136) !important]
2 2022-05-10 19:29:49 4
[color=rgb(119, 120, 136) !important]
3 2022-05-10 19:29:50 5
[color=rgb(119, 120, 136) !important]
4 2022-05-10 19:29:50 NA
[color=rgb(119, 120, 136) !important]
5 2022-05-10 19:29:51 6
[color=rgb(119, 120, 136) !important]
[color=rgba(0, 0, 0, 0.75)]