3
ВозьмитеИспользование `SetKey()` внутри функции
DT <- CJ(1:2, 2:3)
key.the.DT <- function(data.table, primary.key)
setkey(data.table, primary.key)
key.the.DT(data.table = DT, primary.key = 'V1')
возвращается
Error in setkeyv(x, cols, verbose = verbose, physical = physical) :
some columns are not in the data.table: primary.key
Как я могу ввести в data.table внутри функции?
EDIT: Для двух или более клавиш ...
DT <- CJ(1:2, 2:3, 4:5)
key.the.DT <- function(data.table, the.keys)
setkeyv(data.table, the.keys)
setkey(DT, 'V3')
key(DT)
# [1] "V3"
key.the.DT(data.table = DT, the.keys = c('V1', 'V2'))
key(DT)
# [1] "V1" "V2"