title: R Dynamically build "list" in data.table (or ddply)
body: <p>My aggregation needs vary among columns / data.frames. I would like to pass the "list" argument to the data.table dynamically.</p>
  
  <p>As a minimal example:</p>
  
  <pre><code>require(data.table)
  type &lt;- c(rep("hello", 3), rep("bye", 3), rep("ok",3))
  a &lt;- (rep(1:3, 3))
  b &lt;- runif(9)
  c &lt;- runif(9)
  df &lt;- data.frame(cbind(type, a, b, c), stringsAsFactors=F)
  DT &lt;-data.table(df)
  </code></pre>
  
  <p>This call:</p>
  
  <pre><code>DT[, list(suma = sum(as.numeric(a)), meanb = mean(as.numeric(b)), minc = min(as.numeric(c))), by= type]
  </code></pre>
  
  <p>will have result similar to this:</p>
  
  <pre><code>    type suma     meanb      minc
  1: hello    6 0.1332210 0.4265579
  2:   bye    6 0.5680839 0.2993667
  3:    ok    6 0.5694532 0.2069026
  </code></pre>
  
  <p>Future data.frames will have more columns that I will want to summarize differently. But for the sake of working with this small example: Is there a way to pass the list programatically? </p>
  
  <p>I naïvely tried:</p>
  
  <pre><code># create a different list
  mylist &lt;- "list(lengtha = length(as.numeric(a)), maxb = max(as.numeric(b)), meanc = mean(as.numeric(c)))"
  # new call
  DT[, mylist, by=type]
  </code></pre>
  
  <p>With the following error:</p>
  
  <pre><code>1: hello
  2:   bye
  3:    ok
  mylist
  1: list(lengtha = length(as.numeric(a)), maxb = max(as.numeric(b)), meanc = mean(as.numeric(c)))
  2: list(lengtha = length(as.numeric(a)), maxb = max(as.numeric(b)), meanc = mean(as.numeric(c)))
  3: list(lengtha = length(as.numeric(a)), maxb = max(as.numeric(b)), meanc = mean(as.numeric(c)))
  </code></pre>
  
  <p>Any hints appreciated! Best regards!</p>
  
  <p>PS sorry about these <code>as.numeric()</code>, I could not quite figure out why, but I needed them for the example to run. </p>
  
  <p><strong>Minor edit</strong> inserted columns / before data.frame in initial sentence to clarify my needs. </p>