[R] Subscript out of Bounds

From: Dat Mai <dat.d.mai_at_gmail.com>
Date: Thu, 28 Apr 2011 15:49:15 -0400


I currently have this code:

for(j in 2:n){
  for(i in 1:(j-1)){

    # Make sure the inputs are for the matrix "m"     input1=rownames(m)[i]
    input2=colnames(m)[j]

    q=t[(t$Rec1==input1 & t$Rec2==input2),output]

    if(length(q)==0){
      q=t[(t$Rec1==input2 & t$Rec2==input1),output]     }

    m[i,j]=mean(q)
    m[j,i]=mean(q)
    m[j,j]=mean(q)

}}

I already created a 20x20 matrix "m" and have the rows and columns made up:

m=matrix(data=NA, nrow=rl, ncol=rl, dimnames=list(R1=rec.list, R2=rec.list))

the length of a column in the matrix is 20 the length of n is 430

When I run this, the error: "Subscript is out of Bounds" appears when it reaches the m[i,j].
Checking again, the issue is primarily with "j"

How would I go about fixing this issue (nevermind the "mean(q)", as I don't even know if that works and didn't get the chance to explore it)?

        [[alternative HTML version deleted]]



R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Thu 28 Apr 2011 - 19:55:30 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Thu 28 Apr 2011 - 20:20:34 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive