问题描述
我有兴趣计算r sparklyr中最后x秒/分钟的移动时间戳中的唯一观察值。这是移动时间戳记中最后1秒的示例。我想在sparklyr中实现这一目标。如果我要计算最近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:27","2020-08-08 14:04:28","2020-08-08 14:04:29","2020-08-08 14:04:30","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,2,1))
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)