R中的新功能,并尝试在Elo_评级问题中使用while

R中的新功能,并尝试在Elo_评级问题中使用while,r,function,R,Function,#RA(新)=RA(旧)-输了比赛后的KP(A)#评级 #RA(新)=RA(旧)-k1/(1+exp(RB-RA))#赢得比赛后的评级 simulate_Elo<-function(RA_old,max_iterations){ iteration=1 current_rating<-vector() while(-2<=RA_old<=2 & iteration< max_iterations) { wi

#RA(新)=RA(旧)-输了比赛后的KP(A)#评级 #RA(新)=RA(旧)-k1/(1+exp(RB-RA))#赢得比赛后的评级

simulate_Elo<-function(RA_old,max_iterations){
    iteration=1
    current_rating<-vector()
     while(-2<=RA_old<=2 & iteration< max_iterations)
     {
        win<-sample(c(0,1),size=1)   #generate random numbers either lose or win       
     if(win==1){
   current_rating[i]<-RA_old[i]-k*(1-(1/(1+exp(RB-RA))))#rating after winning the game 
   }
else{current_rating[i]<-RA_old[i]-K*(1/(1+exp(RB-RA))) # rating after losing the game 
}
return(current_rating)
     }
}
simulate\u Elo