如何在最近x分/秒内计算移动时间戳中的唯一观察值(给出了示例)?

yrdbyhpb  于 2021-05-27  发布在  Spark
关注(0)|答案(0)|浏览(287)

我对计算过去x秒/分钟内的唯一观察值感兴趣,移动r/yr中的时间戳。下面是移动时间戳中最后1秒的示例。我想在今年实现这一目标。如果我计算的是在过去5秒钟内看到的设备,则时间戳类别应视为与在过去5秒钟内看到的设备类似(介于1秒到5秒之间,2秒到6秒之间,而不是1到5,6到10)


# Sample Example

df<-data.frame(device_id=c("x","y","z"),
           timestamps_start=c("2020-08-08 14:04:23","2020-08-08 14:04:26","2020-08-08 14:04:36"),
           timestamps_end=c("2020-08-08 14:04:28","2020-08-08 14:04:31","2020-08-08 14:04:39"))

# Loading to spark

df1<-copy_to(sc,df,"df")

# Expected output

expected_df<-data.frame(timestamps=c("2020-08-08 14:04:23","2020-08-08 14:04:24","2020-08-08 14:04:25","2020-08-08 14:04:26",
                                 "2020-08-08 14:04:27","2020-08-08 14:04:28","2020-08-08 14:04:29","2020-08-08 14:04:30",
                                 "2020-08-08 14:04:31","2020-08-08 14:04:32","2020-08-08 14:04:33","2020-08-08 14:04:34",
                                 "2020-08-08 14:04:35","2020-08-08 14:04:36","2020-08-08 14:04:37","2020-08-08 14:04:38",
                                 "2020-08-08 14:04:39"),No_Devices=c(1,1,1,2,2,2,1,1,1,0,0,0,0,1,1,1,1))

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题