I want to exponentiate every column specified in .SDcols, by the column number of every column, is that possible?
I think it's possible if one can get information about the columns like col number.
We can use Map
to do this. Suppose, if we are changing the first and second columns ('i1'), specify it in the .SDcols
, and with Map
we apply the function on each column of Subset of Data.table (.SD
) with the corresponding index specified in 'i1' and assign (:=
) the output to the columns.
i1 <- 1:2
dt1[, (i1) := Map(`^`, .SD, i1), .SDcols = i1]
dt1 <- data.table(a = 1:5, b= 6:10, c = 11:15)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With