Linked Questions

Popular Questions

Multiply two subsets to a data.table inline

Asked by At

I am trying to accomplish the following

library(data.table)

DT <- data.table(
  ID=c("b", "b", "b", "a", "a", "c"), 
  a=1:6, 
  b=7:12, 
  c=13:18
)

I am trying to accomplish the following

oldcols <- c("a", "b")
newcols <- c("a_1", "b_1")
DT[, c(..newcols) := DT[, ..ldcols]*1e-2*DT[, "c"]]

this is not working. what am I doing wrong?

Related Questions