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

Categories

0 votes
449 views
in Technique[技术] by (71.8m points)

r - Generating Random Dates

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

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

1 Answer

0 votes
by (71.8m points)

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)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...