Skip to content
Back to formatted view

Raw Message

Message-ID: <AA89BFA18D20A8469B6E05BBC55E4471713D47F2@EXCH10-MBX-06.home.ku.edu>
Date: 2011-10-24T23:23:01Z
From: Md Desa, Zairul Nor Deana Binti
Subject: Create a matrix with increment and element with zero subscript

Hello,
Does anyone knows how to deal with zero subscript in R. I have this code:
for (i in 1:nitems){
+             for (j in 1:ncat-1)  {
+          draw<-matrix(rnorm(nitems*(ncat-1),seed1,seed2),nitems,(ncat-1))
+          d<-( sigma_d*draw ) + mu_d
+         draw<-matrix(rtnorm((nitems*(ncat-1)),mean = seed1, sd = seed2, lower = .1, upper = 1.5),nitems,(ncat-1))
+           d<-(sigma_d*draw) + mu_d
+           write.matrix(cbind(b.i0,d), file = "F:/KU/MIRT group/MIMIC-DIF/R/cpprcode/b0d.dat", sep = "  ")
+             b[i,j]<-b[i,j-1]+d[i,j]
+                }
+             }

The error as following:

Error in b[i, j ] <- b[i, j - 1] + d[i, j] :
  replacement has length zero

I would like to to have a matrix where the first column takes from initial pre-assigned value (b[i,0]+d1), the second column is additive from the first column and a constant d2 that is (b(i,1)=b(i,0)+d1+d2, and so forth. Is there any way that R can read subscript of zero?

Thanks,
Deana