I have this data.table:
DT <- data.table(num=c(1,4,6,7,8,12,13, 15), let=rep(c("A","B"), each=4))
Displayed like this:
num let
1: 1 A
2: 4 A
3: 6 A
4: 7 A
5: 8 B
6: 12 B
7: 13 B
8: 15 B
And I define this function:
f<-function(x){return(c(x+1,x+2))}
I want to get this:
let V1 V2
1: A 2 3
2: A 5 6
3: A 7 8
4: A 8 9
5: B 9 10
6: B 13 14
7: B 14 15
8: B 16 17
I run this code:
DT[,list(f(num)),by=let]
and
DT[,f(num),by=let]
But I get this:
let V1
1: A 2
2: A 5
3: A 7
4: A 8
5: A 3
6: A 6
7: A 8
8: A 9
9: B 9
10: B 13
11: B 14
12: B 16
13: B 10
14: B 14
15: B 15
16: B 17
I would add that I do not want to modify the function f at all.