mercredi 7 octobre 2015

Generating non-numeric random variable form a vector

Assume that I have the following vector:

x<-c("Strongly Agree","Agree","Neutral", "Disagree", "Strongly Disagree")

I simply want to generate a vector z that has 100 elements which are randomly selected from the above vector x. One solution is to generate 100 random integer and restrict their values between 1 to 5 and then assign each of the above nominal values to them. However, their might be a direct function that does the job directly.




Aucun commentaire:

Enregistrer un commentaire