Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to know what's the key in an R data.table?

Tags:

r

data.table

If you are using data.table you can set a key with the function setkey().

But how do you know what columns have already been set as key?

Any function such as getkey()?

like image 300
skan Avatar asked Mar 07 '23 19:03

skan


1 Answers

We can use key to get the keys of the data.table

key(df1)
#[1] "col1" "col2"

data

df1 <- data.table(col1 = 1:5, col2 = 6:10, col3 = 11:15)
setkey(df1, col1, col2)
like image 130
akrun Avatar answered Mar 09 '23 18:03

akrun