mardi 5 décembre 2017

sample sequence of successive integer of an interval

I have a question about sampling: I would like to sample successive number in a vector without replacement. Is there a simple way to do so? For example,

sample(c(1:100), 10, replace = F)
76 99 94 53 12 34  5 82 75 30

gives me 10 number between 1 and 100. Now I would like to have 10 sequence of 3 successive integer without replacement: c(2,3,4), c(10,11,12), c(82,83,84) etc. I would even look for the possibility of sampling 10 sequences of different sizes, the sizes given by a vector like

sizevec <- sample(c(1:4),10,replace = T)

Thanks for the help




Aucun commentaire:

Enregistrer un commentaire