mercredi 7 janvier 2015

Ordering R to restart a function

my problem is strange, I guess. I am trying to make a schedule for volleyball teams at my university and I decided I want to do via R. I have 21 teams and 16 of them are playing every week. Doesn't really matter if some teams have different number of games, because we are going to look at the average results.


So I created a very simple function:


play<-function(group){ for (i in 1:1){ playing<-sample(group,16) in1<-sort(playing) in2<-sample(playing) if( sum(in1==in2)==0 ){ games<-rbind(in1,in2) } if( sum(in1==in2)!=0 ){ i<-i-1 } } return(games) }


What is my problem? R is not helping me! If the two vector in1 and in2 are equal to each other in at least one position, it is not running the function for again. Do you guys have any idea why? Do you have any idea how I could solve this?


Playing are the teams which are playing this week. (Just 16 of them play) group will be a vector with the name of the teams... (You can use A, B, C, D as an example) sample(playing) just randomizes the vector with the 16 chosen teams. When in1 and in2 don't match in any space, we can make the pairs for playing. And while checking this, the problem comes. :/


Can anyone help me? Thanks


Aucun commentaire:

Enregistrer un commentaire