I have a vector of size M = 2630, How can I draw 4 samples of size M/4.
The following code is not working
M <- c(1:2630)
mysample <- split(sample(M), 1:(length(M)/4))
Since (length(M)/4) is not an integer, So I would like to make three samples of equal size and the fourth will have the rest of the units. Three samples can be of size 657 and the fourth one can be 659.
Any help is appreciated
Here is an easy way using a separate index vector
idx:Or you use the
splitfunction:Note that I set a random seed using
set.seedto make the results reproducible.You can use
tableto check the values ofidx: