I have a problem with this function. It gives me the modified data table I want but also changes the original one.
What I want is two different data tables. The input should remain unchanged and the modified one should give me what this exemple gives me.
if (!require('data.table')) {
install.packages('data.table')
}
DT <- data.table(x=rnorm(10, 0, 3), y=rnorm(10, 2, 2))
func <- function(input) {
data <- input
data[x >= abs(1.5), c('trigger') := list(y)]
data[y >= 3.5, c('trigger2') := list(x)]
return (data)
}
DT_modif <- func(DT)
I don't know why I get this side effect.