I would like to apply a function to a data table which has more than 1 arguments.
Assume:
dt<-as.data.table(matrix(c(201,202,201,201,202,202,4,6,9,2,4,5,6,9,7,3,2,1), nrow = 6, ncol = 3, byrow = FALSE))
V1 V2 V3
1: 201 4 6
2: 202 6 9
3: 201 9 7
4: 201 2 3
5: 202 4 2
6: 202 5 1
I would like to apply a function with 3 arguments. For the sake of simplicity let's take a sum of them.
Obviously solution is not dt[,sum:=V1+V2+V3]
If I would pass 2nd and 3rd arguments in following way, it does not work.
dt[,sum:=lapply(V1,function(x,y,z) x+y+z,y=V2,z=V3)]
What is the proper way of applying a function with more than 1 arguments?