title: How to compare two adjacent strings in one column and traverse all the strings?
body: <p>The function I used to find difference between two strings (<a href="http://r.789695.n4.nabble.com/Comparing-diffing-strings-td2336741.html" rel="nofollow">found on the R-help website</a>):</p>
  
  <pre><code>X  &lt;- "abcdefg" ; Y &lt;- "aBcDEfg" 
  diff &lt;- function(X,Y){
    X0 &lt;- unlist(strsplit(X,split=""))  ## Nasty but necessary! 
    Y0 &lt;- unlist(strsplit(Y,split=""))  ## ... 
    ix &lt;- which(X0 != Y0) 
    cbind(ix,X0[ix],Y0[ix])   
  }
  diff(X,Y)
       ix         
  [1,] "2" "b" "B"
  [2,] "4" "d" "D"
  [3,] "5" "e" "E"
  </code></pre>
  
  <p>The column in the data frame status I need to compare :</p>
  
  <pre><code>grint &lt;- 
  c("45CCBC44B", "45CCBC44B", "45CCBC44B", "45CCBC44B", "45CCBC44B", 
  "45CCBC44B", "45CCBC44B", "45CCBC44B", "45CCBC44B", "&lt;5CCBC:4B", 
  "&lt;5CCBC:4B", "&lt;5CCBC:4B", "&lt;&lt;CCBC::B", "&lt;&lt;GGBG::E", "&lt;&lt;GGBG::E", 
  "55CCBC41B", "55CCBC41B", "55CCBC41B", "55CCBC41B", "55CCBC41B", 
  "55CCBC41B", "55CCBC41B", "55CCBC41B", "55CCBC41B", "55CCBC41B", 
  "55CCBC41B", "55CCBC41B", "55CCBC41B", "55CCBC41B", "55CCBC41B", 
  "55CCBC41B", "55CCBC41B", "55CCBC41B", "55CCBC41B", "55CCBC41B", 
  "55CCBC41B", "55CCBC41B", "55CCBC41B", "55CCBC41B", "55CCBC41B", 
  "55CCBC41B", "55CCBC41B", "55CCBC41B", "55CCBC41B", "CC11B1CCE", 
  "CC11B1CCE", "CC55B1CCE", "55CCBC44B", "55CCBC44B", "55CCBC44B", 
  "55CCBC44B", "55CCBC44B", "55CCBC44B", "G1CCBC1GB", "G1CCBC1GB", 
  "G1CCBC1GB", "G1CCBC1GB", "G1CCBC1GB", "G1CCBC1GB", "G1CCBC1GB", 
  "G1CCBC1GB", "G1CCBC1GB", "G1CCBC1GB", "G1CCBC1GB", "G1CCBC1GB", 
  "G1CCBC1GB", "G1CCBC1GB", "91CCBC11B", "01CCBC11B", "01CCBC11B", 
  "01CCBC11B", "01CCBC11B", "11CCBC11B", "11CCBC11B", "11CCBC11B", 
  "15CCBC11B", "15CCBC11B", "15CCBC11B", "15CCBC11B", "15CCBC11B", 
  "15CCBC11B", "15CCBC11B", "15CCBC11B", "15CCBC11B", "15CCBC11B", 
  "55CCBC11B", "55CCBC11B", "55CCBC41B", "55CCBC41B", "55CCBC41B", 
  "55CCBC41B", "55CCBC41B", "55CCBC41B", "55CCBC41B", "55CCBC41B", 
  "55CCBC41B", "55CCBC41B", "55CCBC41B", "55CCBC41B", "55CCBC41B"
  )
  </code></pre>
  
  <p>I need to compare the values in the column successively, that means it can find the difference happened and compare the two strings. For example, <code>grint[9]</code> and <code>grint[10]</code> are different and show it. 
  I tried to use <code>lapply</code> function to accomplish a loop to apply to each string to find every changes, but I failed:</p>
  
  <pre><code>a &lt;-grint[i]
  b &lt;-grint[i+1]
  
  lapply(grint,diff(a,b))
  </code></pre>
  
  <p>the error:</p>
  
  <pre><code>Error in match.fun(FUN) : 
    'diff(a, b)' is not a function, character or symbol
  </code></pre>
  
  <p>So I wonder how I should do this? Thanks very much!</p>