How to set several columns as the key in data.table package (r)?

Jiawen

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?

rafa.pereira

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.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Group several columns then aggregate a set of columns in Pandas (It crashes badly compared to R's data.table)

From Dev

subset data with key in R using `data.table` package

From Dev

R data.table package - adding values in columns using := operator

From Dev

R data.table package - adding values in columns using := operator

From Dev

Is there a way to sort columns of a matrix independently in data.table package R

From Dev

Subsetting and assignment on several columns of a data table

From Dev

Subsetting and assignment on several columns of a data table

From Dev

Set attributes to multiple data.table columns in R

From Dev

Set R data.table row order by chaining 2 columns

From Dev

r data.table set key column length error

From Dev

How does data.table sort NA values on key columns?

From Dev

Mysql - how to get data for two foreign key columns of same table

From Dev

Remove rows from data.table in R based on values of several columns

From Dev

How to set multiple columns in a data table to values from different columns in the same data table?

From Dev

How to set AJAX response to jquery data table columns?

From Dev

How to set Primary key to 1 after delete table data?

From Dev

How to set Primary key to 1 after delete table data?

From Dev

how to concatenate 2 columns in the same data set in R

From Dev

Using data.table package in R to sum over columns - getting GForce sum(gsum) error

From Dev

Using data.table package in R to sum over columns - getting GForce sum(gsum) error

From Dev

How to select the columns by the content in another column in data.table of R?

From Dev

R: How to calculate lag for multiple columns by group for data table

From Dev

How to update all columns of a R data.table by row?

From Dev

R: How to select columns in a data table depending on column variance?

From Dev

Weighted means for several columns, by groups (in a data.table)

From Dev

How to subset a data table according to several conditions

From Dev

How to pick a primary key in a relational database when several columns are unique?

From Dev

R data.table - searching for multiple rows by key which is composed of 2 columns

From Dev

R: Fast Subsetting Large Data Table Conditioned on Key Words in One of the Columns

Related Related

  1. 1

    Group several columns then aggregate a set of columns in Pandas (It crashes badly compared to R's data.table)

  2. 2

    subset data with key in R using `data.table` package

  3. 3

    R data.table package - adding values in columns using := operator

  4. 4

    R data.table package - adding values in columns using := operator

  5. 5

    Is there a way to sort columns of a matrix independently in data.table package R

  6. 6

    Subsetting and assignment on several columns of a data table

  7. 7

    Subsetting and assignment on several columns of a data table

  8. 8

    Set attributes to multiple data.table columns in R

  9. 9

    Set R data.table row order by chaining 2 columns

  10. 10

    r data.table set key column length error

  11. 11

    How does data.table sort NA values on key columns?

  12. 12

    Mysql - how to get data for two foreign key columns of same table

  13. 13

    Remove rows from data.table in R based on values of several columns

  14. 14

    How to set multiple columns in a data table to values from different columns in the same data table?

  15. 15

    How to set AJAX response to jquery data table columns?

  16. 16

    How to set Primary key to 1 after delete table data?

  17. 17

    How to set Primary key to 1 after delete table data?

  18. 18

    how to concatenate 2 columns in the same data set in R

  19. 19

    Using data.table package in R to sum over columns - getting GForce sum(gsum) error

  20. 20

    Using data.table package in R to sum over columns - getting GForce sum(gsum) error

  21. 21

    How to select the columns by the content in another column in data.table of R?

  22. 22

    R: How to calculate lag for multiple columns by group for data table

  23. 23

    How to update all columns of a R data.table by row?

  24. 24

    R: How to select columns in a data table depending on column variance?

  25. 25

    Weighted means for several columns, by groups (in a data.table)

  26. 26

    How to subset a data table according to several conditions

  27. 27

    How to pick a primary key in a relational database when several columns are unique?

  28. 28

    R data.table - searching for multiple rows by key which is composed of 2 columns

  29. 29

    R: Fast Subsetting Large Data Table Conditioned on Key Words in One of the Columns

HotTag

Archive