Suppose, we have data.table with some columns:
DT <- data.table(c1 = c(1, 2, 3), c2 = c(1, 2, 3), ...)
and have function which returns data.frame:
fn_ret_df <- function(val1, val2) {
return(data.frame(newC1 = val1^2, newC2 = val2/2))
}
How to concat initial DT and results of fn_ret_df(c1, c2) after applying for each line?
Here's what works for me now, but it has memory consumption problem:
DT[, cbind(fn_ret_df(c1, c2), c1, c2)]