Dear all,
We are encountering a problem with our code in a particular replication. We
can use this for one set of our data and get the (more or less) right
numbers:
out2<- matrix(NA,2,2)
out2[,1] <- c(34, 36)
varnames <- colnames(plomin)
rownames(out2) <- varnames[out2[,1]]
for ( i in 1:2){ # Calculate teacher assessment correlations for MZ twins at
7
out2[i,2] <- cor(mat.cmz1[,2*(16+i)],mat.cmz1[,2*(16+i)+1], use =
"complete")
}
out2
But when we try to use the same code with different column numbers for a
different portion of the data, we get an error:
out6<- matrix(NA,3,2)
out6[,1] <- c(103,105,107)
varnames <- colnames(plomin)
rownames(out6) <- varnames[out6[,1]]
for ( i in 1:3){ # Calculate teacher assessment correlations for MZ twins at
10
+ out6[i,3] <- cor(mat.cmz3[,2*(51+i)],
mat.cmz3[,2*(50+i)+1],use="complete")
+ }
Error in out6[i, 3] <- cor(mat.cmz3[, 2 * (51 + i)], mat.cmz3[, 2 * (50 + :
subscript out of bounds
+ out6
We've tried rewriting the code in that line in many different ways, such
that the elements are reordered, we've written it from scratch, we've taken
out all the spaces and we can't seem to get it to read beyond that '+'
sign
in that line. Does anyone have any clue as to why we would get the error in
one but not the other?
Thanks.
Best,
Jill & Jeremy