data.table: using setkey with a column name variable

后端 未结 1 1994
说谎
说谎 2021-01-04 00:20

I have a variable name saved into the string variable which_id.

W is a data.table. How do I call setkey on W with

相关标签:
1条回答
  • 2021-01-04 01:04

    setkeyv should work. Here is a reproducible example:

    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
    
    0 讨论(0)
提交回复
热议问题