title: Row indices in data.table in R
body: <p>How do I control the row indices in data.table in R?</p>
  
  <p>I want to check if the value in a row matches the previous one:</p>
  
  <pre><code>patient    produkt    output
  1          Meg        Initiation
  1          Meg        Continue
  1          Gem        Switch
  2          Pol        Initiation
  2          Pol        Continue
  2          Pol        Continue
  </code></pre>
  
  <p>Where the output column is the output, I wish (could be replaced with numbers if that is easier though such that <code>initiation=0, continue=1, switch=2</code>).</p>
  
  <p>I can't find out how to control the indices in data.table, and the following does not work</p>
  
  <pre><code>test[ , switcher2 := identical(produkt, produkt[-1]),by=patient]
  </code></pre>
  
  <p>Any ideas are welcome. It has to be in a data.table though.</p>