0

I have a vector generator, which in every step add to a vector X one random element from 1 to 10. It means, that in step 1, X has 1 random element from 1 to 10, in step 2, I add to a X one random element from 1 to 10. That is what I have so far.

But I need help with the next step.

The process must stop when in the vector X are all the elements from 1 to 10. For example, if in step 20 I have in X only elements from 1 to 9 and number 10 is not in X, the process stops when the number 10 is generated.

In every step of generator I want to test, if the X contains all the elements - it means, that I want to test if the vector X contains the vector Y = [1, 2, ..., 10] How can I test that the vector contains elements from another vector?

Ian Campbell
  • 23,484
  • 14
  • 36
  • 57

1 Answers1

0
X<-c()
while(sum(1:10 %in% X)<10 ) {
  X<-c(X,sample(1:10,1))
}
# to check whether the resultant X is correct or not
sort(unique(X))

try this, by the way, provide a minimum reproducible sample is very helpful for you to get the desired solution. Do search before simply ask.

Jia Gao
  • 1,172
  • 3
  • 13
  • 26