I am trying to understand how .SDcols and .SD work. I got the following function which I can apply directly in datatable, but not via lapply. I am wondering if there is an equivalent with .SD which allows to pass multiple parameters to the function body. The below code always gives "Unused argument..."
DT <- data.table(a=1:10,b=2:11,c=3:12,ID=c(rep("A",5),rep("B",5)))
doSomething <- function(a,b,c){
tmp <- a/b
tmp2 <- sqrt(tmp)^2000000
tmp3 <- tmp2 + tmp
return(rep(tmp3,length(a)))
}
DT[,doSomething(a,b,c)] # works
DT[,lapply(.SD,doSomething,a,b,c),.SDcol=c("a","b","c")]
DT[,lapply(.SD,doSomething,a=a,b=b,c=c),.SDcol=c("a","b","c")]