title: How to use apply instead of for loop for stringMatch function?
body: <p>I'm trying to calculate the number of pairwise differences between a long list of sequences, and put it back into a matrix form. This is a toy example of what I want to do.</p>
  
  <pre><code>library(MiscPsycho)
  b &lt;- c("-BC", "ACB", "---") # Toy example of sequences
  workb &lt;- expand.grid(b,b)
  new &lt;- c(1:9)
  
  # Need to get rid of this for loop somehow
  for (i in 1:9) {
  new[i] &lt;- stringMatch(workb[i,1], workb[i,2], normalize="NO")
  }
  
  workb &lt;- cbind(workb, new)
  newmat &lt;- reShape(workb$new, id=workb$Var1, colvar=workb$Var2)
  
  a &lt;- c("Subject1", "Subject2", "Subject3") #Relating it back to the subject ID
  colnames(newmat) &lt;- a
  rownames(newmat) &lt;- a
  newmat
  </code></pre>
  
  <p>I'm not very familiar with using the apply functions, but I'd like to use it to be able to replace the for loop, which will probably get slow considering I have a large number of sequences. (The stringMatch function is from MiscPsycho). Please let me know how to make it more efficient!</p>
  
  <p>Thank you very much! </p>