title: data.table, apply function to portion of a table
body: <p>I want to apply function to portion of a table.</p>
  <p>With data.frame, no problem:</p>
  <pre><code>df &lt;- data.frame(name = paste(&quot;a&quot;, 1:10, sep = &quot;-&quot;),
                   x = 1:10,
                   y = rep(1:5),
                   z = rep(1:2, each = 5))
  
  df[2:5, -1] &lt;- scale(df[2:5, -1], center = c(1,2,3), scale = c(4,5,6))
  </code></pre>
  <p>But data.table complains:</p>
  <pre><code>dt &lt;- data.table(name = paste(&quot;a&quot;, 1:10, sep = &quot;-&quot;),
                   x = 1:10,
                   y = rep(1:5),
                   z = rep(1:2, each = 5))
  
  
  dt[2:5, -1] &lt;- scale(dt[2:5, -1], center = c(1,2,3), scale = c(4,5,6))
  </code></pre>
  <blockquote>
  <p>Error in <code>[&lt;-.data.table</code>(<code>*tmp*</code>, 2:5, -1, value = c(0.25, 0.5, 0.75,  :
  Item 1 of column numbers in j is -1 which is outside range [1,ncol=4]. Use column names
  instead in j to add new columns.</p>
  </blockquote>
  <p>What is the correct way in data.table?  Thanks!</p>