How can I use a fixed specific column argument ... lapply(.SD, FUN, ...)
Example
DT <- data.table(id_column = rnorm(10),
x1 = rnorm(10), x2 = rnorm(10), x3 = rnorm(10))
measure_col = paste0("x",1:3)
DT[,lapply(.SD, cov, y=id_column), .SDcols = measure_col]
Results in
Error in is.data.frame(y) : object 'id_column' not found
A possible workaround would be
DT[,lapply(.SD, cov, y = DT[,id_column]), .SDcols = measure_col]
x1 x2 x3
1: 0.1703253 -0.2831533 0.3387133
Is there a better way to do this? Not referring to y ony=DT[,id_column]
source
share