title: lag row value in R by groups
body: <p>I want the previous row value for different groups. I have gone through the solution given <a href="https://stackoverflow.com/questions/26291988/how-to-create-a-lag-variable-within-each-group">here</a> and also tried the code shown below.</p>
  
  <pre><code>new_data[,avg_week := shift(.(avg_travel_time),type = "lag"), by = identifier]
  </code></pre>
  
  <p>This is the error that I am getting.</p>
  
  <pre><code>Error in `[.data.frame`(new_data, , `:=`(avg_week, c(NA, avg_travel_time[-.N])),  : 
  unused argument (by = identifier)
  </code></pre>