Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>This now works in v1.8.3 on R-Forge. Thanks for highlighting it!</p> <pre><code>x &lt;- data.table(a = 1:3, b = 1:6) f &lt;- function(x) {list("hi", "hello")} x[ , c("col1", "col2") := f(), by = a][] # a b col1 col2 # 1: 1 1 hi hello # 2: 2 2 hi hello # 3: 3 3 hi hello # 4: 1 4 hi hello # 5: 2 5 hi hello # 6: 3 6 hi hello x[ , c("mean", "sum") := list(mean(b), sum(b)), by = a][] # a b col1 col2 mean sum # 1: 1 1 hi hello 2.5 5 # 2: 2 2 hi hello 3.5 7 # 3: 3 3 hi hello 4.5 9 # 4: 1 4 hi hello 2.5 5 # 5: 2 5 hi hello 3.5 7 # 6: 3 6 hi hello 4.5 9 mynames = c("Name1", "Longer%") x[ , (mynames) := list(mean(b) * 4, sum(b) * 3), by = a] # a b col1 col2 mean sum Name1 Longer% # 1: 1 1 hi hello 2.5 5 10 15 # 2: 2 2 hi hello 3.5 7 14 21 # 3: 3 3 hi hello 4.5 9 18 27 # 4: 1 4 hi hello 2.5 5 10 15 # 5: 2 5 hi hello 3.5 7 14 21 # 6: 3 6 hi hello 4.5 9 18 27 </code></pre> <p><br></p> <pre><code>x[ , mynames := list(mean(b) * 4, sum(b) * 3), by = a, with = FALSE][] # same # a b col1 col2 mean sum Name1 Longer% # 1: 1 1 hi hello 2.5 5 10 15 # 2: 2 2 hi hello 3.5 7 14 21 # 3: 3 3 hi hello 4.5 9 18 27 # 4: 1 4 hi hello 2.5 5 10 15 # 5: 2 5 hi hello 3.5 7 14 21 # 6: 3 6 hi hello 4.5 9 18 27 x[ , get("mynames") := list(mean(b) * 4, sum(b) * 3), by = a][] # same # a b col1 col2 mean sum Name1 Longer% # 1: 1 1 hi hello 2.5 5 10 15 # 2: 2 2 hi hello 3.5 7 14 21 # 3: 3 3 hi hello 4.5 9 18 27 # 4: 1 4 hi hello 2.5 5 10 15 # 5: 2 5 hi hello 3.5 7 14 21 # 6: 3 6 hi hello 4.5 9 18 27 x[ , eval(mynames) := list(mean(b) * 4, sum(b) * 3), by = a][] # same # a b col1 col2 mean sum Name1 Longer% # 1: 1 1 hi hello 2.5 5 10 15 # 2: 2 2 hi hello 3.5 7 14 21 # 3: 3 3 hi hello 4.5 9 18 27 # 4: 1 4 hi hello 2.5 5 10 15 # 5: 2 5 hi hello 3.5 7 14 21 # 6: 3 6 hi hello 4.5 9 18 27 </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload