产生随机日期 [英] Generating Random Dates
本文介绍了产生随机日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在特定日期范围内生成一组12个随机日期?
How can I generate a set of 12 random dates within a specific date range?
我认为以下方法会起作用:
I thought the following would work:
sample(as.Date(1999/01/01), as.Date(2000/01/01),12)
但是结果看起来像是一组随机数字?
But the result looks like a random set of numbers?
谢谢
推荐答案
seq
具有用于类 Date <的方法。 / code>对此适用:
seq
has a method for class Date
which works for this:
sample(seq(as.Date('1999/01/01'), as.Date('2000/01/01'), by="day"), 12)
这篇关于产生随机日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文