r - data.table: using setkey with a column name variable -
i have variable name saved string variable which_id.
w data.table. how call setkey on w which_id ?
this i've tried
> eval( paste( 'setkey(w,' , which_id , ')' ) ) [1] "setkey(w, customer_id_a )" but call tables() shows customer_id_a key didn't take.
> evalq( paste( 'setkey(w,' , which_id , ')' ) ) [1] "setkey(w, customer_id_a )" customer_id_a key still didn't take.
> setkeyv( w , cols=which_id ) and
> setkeyv( w , cols=c( which_id ) ) --> same thing, customer_id_a key isn't there.
any pointers? thanks.
setkeyv should work. here 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
Comments
Post a Comment