I have a variable name saved into the string variable which_id.
which_id
W is a data.table. How do I call setkey on W with
W
setkey
setkeyv should work. Here is a reproducible example:
setkeyv
library(data.table) W <- data.table(customer_id_A = 1:2) which_id <- "customer_id_A" setkeyv(W, which_id) tables() ## NAME NROW MB COLS KEY ## [1,] W 2 1 customer_id_A customer_id_A ## Total: 1MB