I have the following data.table:
name = c("Bob","Mary","Jane","Kim")
weight = c(60,65,45,55)
height = c(170,165,140,135)
dft = data.table(name,weight,height)
I want to change weight
to be equal to height + 13
. I know numerous ways can do this, for example
dft[, weight := height + 13
or
dft[, "weight" := height + 13
However, since I have a huge dataset whose column names are like V1, V2,....,V1000
, I wish to use column names to enter modification. In the above example, however,
dft[, "weight" := "height" + 13
is not working.
So I wonder how to use "height"
to modify weight
. Thanks