mystring<- sample (1:3, size=100)
I want to generate randomly this string of numbers, but I want that the probability of 2 to be 0.25 and those of 1 and 3 to be 0.375 and 0.375 respectively.
CodePudding user response:
We can specify probabilities using prob=c()
mystring <-sample(1:3,size=10000,replace=TRUE,prob=c(0.375,0.25,0.375))
Output:
table(mystring)
1 2 3
3752 2493 3755