0

I need help on the following code

I tried to generate a random series using while clause and met the following problem

When run codes as below

m1=0.82
set=rep(1, 1000)

while(mean(set)!=m1){
 k=sample(1:1000,1)
 if(set[k]!=0){set[k]=0}

 }

every thing is fine, however the loop can end if I change ml as as below

 m1=1-0.18
set=rep(1, 1000)

while(mean(set)!=m1){
 k=sample(1:1000,1)
if(set[k]!=0){set[k]=0}

}

just change from ml=0.82 to ml=1-0.18, R can't stop looping.

0 Answers0