Error in * tmp * [[j]]: index outside

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 #11

2: `[<-`(`*tmp*`, row, 1, value = NULL) at #11

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!

+5
source share
1

data.frame [<-.data.frame. ( rbind.) , , data.frame. "C" - 0 , . "C", . , , , .

, , :

teams <- sort(unique(c(games[,1], games[,2])), decreasing = FALSE) 
T <- data.frame(Team=teams,  ... )

... , , . $<- , .

+4

All Articles