簡體   English   中英

R 的新手,在我的函數中收到錯誤

[英]new to R, receiving an error in my function

true_RA<-seq(-2,2 ,length.out = 13)  #true vector with -2<RA<2 in
# even intervals for 13 players 

true_RA

current_RA<-true_RA   #assign true_RA to the current ratings

ratings_overtime<-matrix(current_RA, nrow=13, ncol=10,000) #create a #matrix of 13 players
# and 10000 ratings 

p<-0.5825702

simulate_game<-function(i,j){
    old_RA_i<-current_RA[i] #assign the rate from 
#my current rating vector from vector 

    old_RA_j<-current_RA[j]
    win<rbinom(1,1,p)
if (win==1){current_RA_i<-old_RA_j+400}
else{current_RA_j<-old_RA_i+400}
}  
 return(c(current_RA_i,current_RA_j))
}

根據rbinom(1,1,p)的真實基本評級,我的函數應該模擬玩家 i 和 j 之間的游戲。 我收到一個錯誤:找不到對象“current_RA_i”。

你有一個額外的大括號,所以函數在return語句之前結束。

由於current_RA_icurrent_RA_j變量是在函數內定義的,它們的作用域不是全局的,因此在函數結束后沒有任何值。

return語句之前刪除}字符應該可以解決錯誤。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM