I have a large data.table in R and would like to set any negative numbers in a subset of columns to zero. I have looked at multiple options for doing this but I can't find answer I need.
For example if I have the following data.table:
v1 <- c(-32, -45, -92, 0, 11)
v2 <- c(10, 12, -9, -3, 5)
v3 <- c(-12, -65, 10, 4, -9)
v4 <- c(-54, 45, 65, 34, -12)
DT <- as.data.table(cbind(v1, v2, v3, v4))
While I could convert ALL negative values to 0 with this:
DT[DT<0] <- 0
How could I set only the negative values in v2 and v3 to zero? I feel like this should be simple but the answer is escaping me.
Thank you in advance (and if the answer exists elsewhere please do direct me to it).