mercredi 12 juin 2019

sample() function excluding reoccuring values R

I want to choose random values of a vector and print them without having the possibility of reoccuring the same numbers. E.g If 32 has already been printed out, it should not be possible to print this number (or save this number in another variable) again. How can I do this?

test <- c(1,32,4,92,20)
for (i in 1:4){
  print(sample(test,size = 1))}




Aucun commentaire:

Enregistrer un commentaire