有没有一种方法可以生成随机的“时间”?

时间:2018-07-26 14:36:46

标签: r random time sampling

我知道您可以使用as.POSIXct来生成日期和时间。但是我只想生成时间ex)05:16(min:sec) 有人知道怎么做吗?我暂时找不到任何包裹。

1 个答案:

答案 0 :(得分:1)

library(lubridate) > sample(as.duration(0:599), 30) [1] "345s (~5.75 minutes)" "277s (~4.62 minutes)" "74s (~1.23 minutes)" [4] "15s" "571s (~9.52 minutes)" "186s (~3.1 minutes)" [7] "45s" "355s (~5.92 minutes)" "121s (~2.02 minutes)" [10] "488s (~8.13 minutes)" "179s (~2.98 minutes)" "371s (~6.18 minutes)" [13] "515s (~8.58 minutes)" "31s" "346s (~5.77 minutes)" [16] "0s" "398s (~6.63 minutes)" "84s (~1.4 minutes)" [19] "160s (~2.67 minutes)" "457s (~7.62 minutes)" "94s (~1.57 minutes)" [22] "212s (~3.53 minutes)" "591s (~9.85 minutes)" "576s (~9.6 minutes)" [25] "348s (~5.8 minutes)" "314s (~5.23 minutes)" "563s (~9.38 minutes)" [28] "509s (~8.48 minutes)" "538s (~8.97 minutes)" "71s (~1.18 minutes)" 是目前处理时间最友好的软件包。只需生成所需的时间间隔并从中进行采样:

DefaultValue

检查函数interval()和ms()以获得获取所需内容的其他可能方式。

但是正如评论中所指出的那样,如果您只需要几秒钟的随机间隔,那么使用整数将更简单,更方便。