A bit of a bizarre case: I have code that creates 2x2 matrices and populates them with particular values, then generates other matrices with lengths equal to the cell values in the first matrices. When I look at the values in the matrix, I get one result - and when I go to generate the lists, they act as a completely different number.
For example, the relevant code, running on R 3.2.2
N <-100
pa <-.3
pna <- .4
pb <-.1
pnb <-.2
table.nH <- matrix(nrow=2,ncol=2)
table.nH[1,1] <- (1-pna)*(1-pnb)*N
table.nH[2,1] <- (1-pa)*(1-pnb)*N
table.nH[1,1] #This should be 48
> [1] 48
table.nH[2,1] #This should be 56
> [1] 56
pass.list <- matrix(rep(c(0,0,0,0),table.nH[1,1]),ncol=4,byrow=TRUE)
fail.list <- matrix(rep(c(0,0,0,0),table.nH[2,1]),ncol=4,byrow=TRUE)
length(pass.list[,1]) #Number of rows *should be* 48
> [1] 48
length(fail.list[,1]) #Number of rows *should be* 56
> [1] 55
I can't for the life of me figure out why one works but the other doesn't. It works if I hard-code the 56 (i.e. rep(c(0,0,0,0),56)) but not if I reference the 56 in the matrix. The actual table in question has no NA values, and this isn't unique (I see it on other versions of the same problem for some reason). However, it's also not universal: some other tables generated this way work exactly as expected.
What's going on, and how can I fix it?