R data.table apply function to rows using columns as arguments
The most elegant way I've found is with mapply
:
x[, value := mapply(func.text, f1, f2)]
x
# f1 f2 value
# 1: 1 3 21.08554
# 2: 2 4 56.59815
# 3: 3 5 151.4132
Or with the purrr
package:
x[, value := purrr::pmap_dbl(.(f1, f2), func.text)]
The best way is to write a vectorized function, but if you can't, then perhaps this will do:
x[, func.text(f1, f2), by = seq_len(nrow(x))]