title: Compute Time Delta in R data.table
body: <p>I have a data table of basketball player data which includes the game date for each game and multiple players. I want to create a column that computes the number of days since the previous game. I'm using the data.table package in R. </p>
  
  <pre><code>   PLAYERID GAME_DATE
  1:     2989 2014-01-1
  2:     2989 2014-01-3
  </code></pre>
  
  <p>I'm using the following code:</p>
  
  <pre><code>DT[, DAY_DIFF:=diff(GAME_DATE, lag=1), by=PLAYERID]
  </code></pre>
  
  <p>it returns:</p>
  
  <pre><code>   PLAYERID GAME_DATE DAY_DIFF
  1:     2989 2014-01-1 2
  2:     2989 2014-01-3 2
  </code></pre>
  
  <p>where it appends the number of days until the next game for every row except the last. In the last row, it appends the number of days since the previous game, the value I want.  I want to put an NA in the first row because it is the first game. </p>