title: R Data.Table Arithmetic Count
body: <pre><code>data=data.table("Student"=c(1,1,1,1,1,2,2,3,3,3,4,4,5,5,5,5,5),
  "X1"=c(0,0,1,1,1,0,2,0,0,2,0,1,0,0,0,1,2))
  </code></pre>
  
  <p>I wish to count three objects. </p>
  
  <p>First I wish to count how many Student have an 1 in the X1 column.</p>
  
  <p>Second I wish to count how many Student have 2 in the X1 column before a 1.</p>
  
  <p>Three I wish to count how many Student have 2 in the X1 column after a 1.</p>
  
  <p>I seek data.table solution</p>