I've come across this post on how to replace occurrences of a number in all columns of a data frame (e.g. replace all 4 by 10 in all columns): DF[DF == 4] <- 10
. With data tables the same results can be achieved in exactly the same way: DT[DT == 4] <- 10
.
However, how should I procede if I want to apply this modification but only to specific columns from the data table, whether these columns are specified by position (e.g. 2:4
) or by name (e.g. c("V2", "V3", "V4")
)?
I will favor an "elegant" solution rather than iterations over every column.