You can use seq()
, e.g.
library(lubridate)
date1<-ymd("2021/01/01")
date2<-ymd("2021/01/31")
seq(date1, date2, length.out = 10)
>[1] "2021-01-01" "2021-01-04" "2021-01-07" "2021-01-11"
>[5] "2021-01-14" "2021-01-17" "2021-01-21" "2021-01-24"
>[9] "2021-01-27" "2021-01-31"
If you want 10 random dates:
library(lubridate)
date1<-ymd("2021/01/01")
date2<-ymd("2021/01/31")
dates <- seq(date1, date2, 1)
sample(dates, 10)
>[1] "2021-01-08" "2021-01-03" "2021-01-20" "2021-01-27"
>[5] "2021-01-02" "2021-01-17" "2021-01-19" "2021-01-30"
>[9] "2021-01-11" "2021-01-05"
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…