简体   繁体   English

如何在 R 中创建时间循环系列

[英]How to create a time loop series in R

My group and I recently started working with R but have however ran into a problem with creating a time loop series for about 15,000 entries.我和我的团队最近开始使用 R,但在为大约 15,000 个条目创建时间循环系列时遇到了问题。 We want it to be from 00:00 til 23:59 for all entries so we're able to calculate each one of them.我们希望所有条目的时间都是从 00:00 到 23:59,这样我们就可以计算每个条目。 We were thinking of creating a separate column for time but have no idea how that's done for 15,00 entries.我们正在考虑为时间创建一个单独的列,但不知道如何为 15,00 个条目完成。

Sample data:样本数据:

df = data.frame( id = c(1, 2, 3, 4), Timeoutside = c(08:30:46.000, 07:20:18.000, 07:46:08.000, 07:27:44.000), Timeinside = c(13:36:40.000, 10:04:40.000, 11:59:05.000, 12:22:05.000)

library(data.table)
n = 15000
ans <- seq(as.ITime("00:00"), as.ITime("23:59:59"), length.out = n)
#"00:00:00" "00:00:05" "00:00:11" "00:00:17" "00:00:23" "00:00:28"
# ...
# ...
# ...
# "23:59:30" "23:59:35" "23:59:41" "23:59:47" "23:59:53" "23:59:59"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM