title: R + Applying function on multiple columns , while creating new columns, by group in data.table
body: <p>I searched for similar cases here, but did not found the right one. They are all slightly different.
  Consider following data.table:</p>
  <pre><code>dt &lt;- data.table(id=c(1,1,2,2),col1=c(1:4),col2=c(2:5),col3=c(3:6))
  </code></pre>
  <p>What I need is to create in the same dt, 3 new difference columns for each columns, group by id.
  I tried it with:</p>
  <pre><code>changeCols &lt;- c(&quot;col1&quot;,&quot;col2&quot;,&quot;col3&quot;)
  newCols &lt;- paste0(changeCols, &quot;_diff&quot;)
  dt[,(newCols):=lapply(.SD, changeCols-shift(changeCols)),by=id, .SDCols=changeCols]
  </code></pre>
  <p>But the syntax seems to be wrong.</p>
  <p>Appriciate any help!</p>