Apologies for the long post! I am new to R and have worked hard to improve my language team. I came across this interesting project for modeling football results: http://www1.maths.leeds.ac.uk/~voss/projects/2010-sports/JamesGardner.pdf
I continue to encounter problems running code to simulate a full season (first mentioned page 36, appendix on page 59):
Games <- function(parameters)
{
teams <- rownames(parameters)
P <- parameters$teams
home <- parameters$home
n <- length(teams)
C <- data.frame()
row <- 1
for (i in 1:n) {
for (j in 1:n) {
if (i != j) {
C[row,1] <- teams[i]
C[row,2] <- teams[j]
C[row,3] <- rpois(1, exp(P[i,]$Attack - P[j,]$Defence + home))
C[row,4] <- rpois(1, exp(P[j,]$Attack - P[i,]$Defence))
row <- row + 1
}
}
}
return(C)
}
Games(TeamParameters)
The answer I get is
Error in `*tmp*`[[j]] : subscript out of bounds
When I try to pass traceback (), this is what I get:
3: `[<-.data.frame`(`*tmp*`, row, 1, value = NULL) at
2: `[<-`(`*tmp*`, row, 1, value = NULL) at
1: Games(TeamParameters)
I really don't understand what the error means, and I would appreciate any help. Once again, apologies for the long post, but I'm really interested in this project and would like to know what the problem is!
source
share