title: R: Compare values in a read table and update another matrix
body: <p>I am currently having a problem utilizing R to compare each column within a specific matrix. I have attempted to compare each of the entire columns at once, and generate a true and false output via the table command, and then convert the number of trues that can be found to a numeric value and input such values in their respective places within the incidence matrix. </p>
  
  <pre><code>For example, I have data in this type of format:
  //Example state matrix - I am attempting to compare c1 with c2, then c1 with c3, then c1 with c4 and so on and so forth 
      c1  c2  c3  c4
  r1  2   6   3   2
  r2  1   1   6   5
  r3  3   1   3   6
  
  And I am trying to instead put it into this format
  //Example incidence matrix - Which is how many times c1 equaled c2 in the above matrix 
      c1  c2  c3  c4
  c1  3   1   1   1
  c2  1   3   0   0
  c3  1   0   3   0
  c4  1   0   0   3
  </code></pre>
  
  <h1>Here is the code I have come up with so far, however, I keep getting this particular error --</h1>
  
  Warning message:
  In IncidenceMat[rat][r] = IncidenceMat[rat][r] + as.numeric(instances) :number of items to replace is not a multiple of replacement length
  
  <pre><code>rawData = read.table("5-14-2014streamW636PPstate.txt")
  colnames = names(rawData) #the column names in R 
  df &lt;- data.frame(rawData)
  rats = ncol(rawData) 
  instances = nrow(rawData)
  
  IncidenceMat = matrix(rep(0, rats), nrow = rats, ncol = rats) 
  
  for(rat in rats)
     for(r in rats)
        if(rat == r){rawData[instance][rat] == rawData[instance][r] something like this would work in C++ if I attempted, 
          IncidenceMat[rat][r] = IncidenceMat[rat][r] + as.numeric(instances)
    } else{ 
      count = df[colnames[rat]] == df[colnames[r]]
      c = table(count)
      TotTrue = as.numeric(c[2][1])
      IncidenceMat[rat][r] = IncidenceMat[rat][r] + TotTrue #count would go here #this should work like a charm as well 
    }
  </code></pre>
  
  <p>Any help would be greatly appreciated; I have also looked at some of these resources, however, I am still stumped</p>
  
  <p><a href="https://stat.ethz.ch/pipermail/r-help/2004-September/058205.html" rel="nofollow noreferrer">I tried this</a> <a href="https://stackoverflow.com/questions/22099461/r-number-of-items-to-replace-is-not-a-multiple-of-replacement-length-results-h">and this</a> along with some other resources I recently closed.</p>