Considering the date samples:
t_s<-seq(as.POSIXct("2010-01-01 00:00:00"), as.POSIXct("2010-12-31 23:00:00"), by = '1 day')
and a date vector:
t<-seq(as.POSIXct("2010-02-01 00:00:00"), as.POSIXct("2010-2-10 23:00:00"), by = '1 day')
Now, I want to randomly sample dates in t_s
with the same weekday of the elements in t
.The sample size should be 4 for each t
element.
For example, the samples for the first element "2010-02-01"
could be "2010-06-28" "2010-5-31" "2010-8-02" "2010-10-04"
because they are all Monday.
The sampled dates from t_s
maybe multipul, beacause some dates in t
share a same weekday. However, if t_s
is much smaller than t
(not in the examplified case), the uniqueness of samples cannot be met. Therefore, sample methods with and without multipul t_s
dates are both wanted.
How could I get these samples?
Something like this should do what you need
Without replacement
With replacement
These return a list with your samples
Excluding previously selected dates