I'm interested in sampling a large dataset in nonconsecutive-record sequences of arbitrary length without overlap. I know from
How to take many samples of 10 from a large list, without replacement overall
how to do it if the sequence length is fixed (at 10 in that example), via
sample <- split(sample(datapoints), rep(1:(length(datapoints)/10+1), each=10))
How do I generalize this to emit uniformly-distributed sized samplings, not just sequences of 10?
Furthermore, can I specify that I want N
such sequences?
For example, suppose I have the sequence d <- 1:20
and permute it via sample(d, 20, replace = F)
to obtain another permuted sequence. Now I want to extract arbitrarily sized subsequences of this permuted sequence, say d1 <- c(1,5,4,15,3)
, d2<- c(18,7,12,11,19,16,10,8,14,17, 20, 13)
, d3 <- c(9,2,6)
in a quick manner as in the example. My dataset is large, and I'd like to simply sample it once, and then split it without any length constraint as in the post I cite.