title: Long table, grouped by factors and refernce to inital position
body: <p>Consider the following MWE. I want to calculate the distance travelled in relation to the initial time step for each person. Take the following:</p>
  
  <pre><code>time &lt;- rep(1:3,2)
  lin.posi &lt;- c(200,175,150,200,190,180)
  person &lt;- c(rep('A', 3), rep('B', 3))
  
  df1 &lt;- data.frame(time, lin.posi, person)
  </code></pre>
  
  <p>I want how far person A is from time=1 for each time step (t=1,2,3) and then calculate the same for person B.</p>
  
  <p>The output should be:</p>
  
  <pre><code># df1$rel.dis &lt;- c(0,25,50,0,10,20)
  </code></pre>
  
  <p>I am have tried to use <code>dplyr</code> but maybe the <code>data.table</code> experts wizards can provide an insight</p>
  
  <pre><code>df1 %&gt;%
    group_by(person) %&gt;% 
    lin.posi[1] - lin.posi
  </code></pre>