skan
skan

Reputation: 7720

How to know what's the key in an 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()?

Upvotes: 7

Views: 3443

Answers (1)

akrun
akrun

Reputation: 886938

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)

Upvotes: 9

Related Questions