We can use Mapfor this. Suppose that if we change the first and second columns ('i1'), specify it in .SDcols, and when Mapwe use the function for each column of the subset Data.table ( .SD) using the corresponding index specified in "i1", and assign ( :=) the output into columns.
i1 <- 1:2
dt1[, (i1) := Map(`^`, .SD, i1), .SDcols = i1]
data
dt1 <- data.table(a = 1:5, b= 6:10, c = 11:15)
akrun source
share