samedi 23 avril 2022

Having trouble creating a function that returns a vector of 5 random numbers from a pool of 20 numbers in R

Total noob here guys, I was asked to do this for a class I am taking and I'm having some trouble as my sample always pulls the same 5 numbers. I'd appreciate any tips that can steer me in the right direction. So far I have this inside the function brackets:

num <-c(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20)

rn = sample(num, 5, replace=T)

This will produce a vector of 5 integers, however, it is always the same 5. How can I fix this so it is always 5 different random numbers?

Thanks




Aucun commentaire:

Enregistrer un commentaire