Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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?

Thank you

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
453 views
Welcome To Ask or Share your Answers For Others

1 Answer

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)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...