jeudi 31 janvier 2019

R Generate random numbers based on condition

I'd like to generate a sequence of 100 numbers based on the following conditions -

  • The numbers range from 1 to 5, and are whole numbers.
  • The number of 1s and 2s generated as a percentage of the total equals 90%

My Attempt

I attempted to create the sequence using runif. However I am unsure about how to include the second condition.

v=c(1,2,3,4,5)
rep(sample(v),100)

Your help on the second condition would be greatly appreciated




Aucun commentaire:

Enregistrer un commentaire