If we have the following data.table:
x <- data.table(`2021` = rep(10, 3), `2022` = rep(5, 3))
we can create a new column like this:
x[, d := `2022` / `2021` -1]
Now I want to save 2022 and 2021 in a vector like this:
years <- c("2021", "2022")
x[, d := years[2] / years[1] -1]
but of course, this doesn't work. I tried to use eval and as.name but it doesn't work in that specific case. How can I achieve that?