setkey()
can be used to set a column as the key to a data table. But now I have three column:
A B C
1 2 3
1 2 4
1 2 5
I want to set the ABC as the key. How to do it in data.table
package?
Three simple alternatives:
# 1
setkeyv(dt, c("A","B","C"))
# 2
keycols = c("A","B","C")
setkeyv(dt, keycols)
# 3, or you can setkey for the whole data.table
setkey(data)
data for example:
library(data.table)
dt <- data.table(A=c(1,1,1), B=c(2,2,2), C=c(3:5))
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments