I need to generate a random
selection of 9 whole numbers from 1 to 40 with the following condition: the output must contain 5 even
numbers and 4 odd
numbers.
I have the following code to generate 9 random numbers:
x1<- sample(1:40, 9, replace=F)
> x1
[1] 2 36 6 10 39 17 14 11 25
I now need to add the odd and even numbers condition in the equation. How can I do this?
Aucun commentaire:
Enregistrer un commentaire