title: data.table: calculate cumulative percentile for all numeric variables
body: <p>I have data like this </p>
  
  <pre><code>set.seed(1)
  dt &lt;- data.table(id = c("A", "A", "B", "B","C", "C"), 
               var1 = c(1:6),
               var2 = rnorm(6))
  
  &gt; dt
     id var1       var2
  1:  A    1 -0.6264538
  2:  A    2  0.1836433
  3:  B    3 -0.8356286
  4:  B    4  1.5952808
  5:  C    5  0.3295078
  6:  C    6 -0.8204684
  </code></pre>
  
  <p>but <strong>with dozens of numeric variables</strong>. I'd like to calculate percentile for each observation and every numeric variable using <code>data.table</code>, while keeping a key identifier (<code>id</code>) intact. In <code>dplyr</code> I could do it like this:</p>
  
  <pre><code>mutate_if(dt, is.numeric, function(x) { ecdf(x)(x) })
  
    id      var1      var2
  1  A 0.1666667 0.5000000
  2  A 0.3333333 0.6666667
  3  B 0.5000000 0.1666667
  4  B 0.6666667 1.0000000
  5  C 0.8333333 0.8333333
  6  C 1.0000000 0.3333333
  </code></pre>
  
  <p>I would be also happy with the result including original <code>var1</code> and <code>var2</code>.</p>
  
  <p>What would be the best way to approach this?</p>
  
  <p>Thanks for help!</p>