r - R 新手,我在运行我的函数时遇到错误
问题描述
random_players <- function(K){
R_two_players <- sample(c(1:13), 2, replace = FALSE)
#select two 2 players randomly
i <- R_two_players[1]
j <- R_two_players[2]
new_rating <- elo_Rating(i, j, K)
# call the function from q-6 in order to have
# access to probability of lose or success of players i and j
return(new_rating)
}
ratings_updated<-matrix(nrow=13, ncol=10000) # is in my global environment
simulate_tournament<-function(K=0.02,n=10000) { #n is the number of games we are simulating
ratings_updated<-matrix(nrow=13, ncol=10000)
for (i in 1:n) {
updated_rate<<-random_players(K) #calling the function from function before to get the new_rating
ratings_updated[,i]<<-updated_rate
}
return(ratings_updated)
}
我收到“ratings_updated[, i] <- updated_rate 错误:矩阵上的下标数量不正确”。我希望每次进入循环时都会更新我的矩阵“ratings_updated”。
解决方案
推荐阅读
- java - E4 无法在类变量上自动注入 MApplication
- ios - 链接器命令在tipsi-twitter 中失败,错误代码为 1
- aws-sdk - 是否可以在不使用 cli 的情况下使用放大框架?
- mysql - 从 2 个表中选择会导致错误
- sqlite - SQLite:.dump 是否复制或重新创建索引?
- solver - GAMS:目标函数中的双指数
- angular - 必须为 formcontrol 提供一个值
- javascript - 是否有 ESLint 或 TSLint 规则检查真/假逻辑运算符是否适用于数字?
- c++ - 当我添加更多单元测试时,为什么工作服的覆盖率不断下降?
- java - List的其他排序方式
在代号一