mardi 6 septembre 2016

Sampling values not in sequence

Is it possible to sample such that it is Okay to have repeated sampling values (i.e. A,B,A ), but it cannot be in sequence(A,A,B), or return just one single value (A,A,A) or (B,B,B). The code below should always give me at least two values, but I don't want the returned values to be in sequence.

x<- 3
alphabet <- LETTERS[seq(1:26)]
a <- sample(alphabet, 2, replace = FALSE)
b <- sample(a, x, replace = TRUE, prob=c(0.5,0.5)) #can't replace
print(b)




Aucun commentaire:

Enregistrer un commentaire