r - R新手,在我的函数中收到错误
问题描述
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))
}
我的函数应该模拟玩家 i 和 j 之间的游戏,因为他们的真实基础评分来自rbinom(1,1,p)
. 我收到一个错误:找不到对象“current_RA_i”。
解决方案
You have an extra close curly bracket, so the function ends before the return
statement.
Since the current_RA_i
and current_RA_j
variables are defined within the function, they are not global in scope, and thus have no value after the function ends.
Removing the }
character just before your return
statement should resolve the error.
推荐阅读
- javascript - Puppeteer:停止冗长的控制台垃圾邮件
- firebase - 无法在我的颤振代码中使用 Firestore 驱动的数据
- sorting - java中时间复杂度O(nlogn)降序排序数组的最小交换
- mysql - 数据表返回列名而不是值
- lua - Love2D 物理不会触发碰撞回调
- android - 为什么导航抽屉项目的点击事件不起作用?
- javascript - 为什么我收到 TypeError:Log.addSales 不是函数
- python - 如果我的部署后需要很长时间,我如何防止我的 Elastic Beanstalk 应用程序显示为不正常?
- powershell - Atom-Juno-Julia 与从 github 安装包和强制 Poweshell 使用 TLS1.2+ 相关的错误消息
- php - PHP数组中的数据条件AND而不是OR