Alireza Izadimehr
Alireza Izadimehr

Reputation: 324

data.table in R : the columns to join by must be specified using 'on=' argument error

I new in R language. i have two data.table like these :

rts:
          id   rt
   1:   10_1 3180
   2:  10_10 1680
   3: 10_100  720
   4:  10_11 1060
   5:  10_16  760

choice:

          id v1 v2 decision   rt condition_id
   1:   10_1  4  2        1 3173          4_2
   2:  10_10  3  3        1 1678          3_3
   3: 10_100  2  2        1  716          2_2
   4:  10_11  6  5        1 1057          6_5
   5:  10_16  5  8        2  760          5_8

when i use this code to select rts in choice :

choice = choice[rts]

i got this error :

Error in `[.data.table`(choice, rts) : 
When i is a data.table (or character vector), the columns to join by must be specified using 'on=' argument (see ?data.table),
by keying x (i.e. sorted, and, marked as sorted, see ?setkey), or by sharing column names between x and i (i.e., a natural join).
Keyed joins might have further speed benefits on very large data due to x being sorted in RAM.

would you please help me? what can i do? thanks.

Upvotes: 2

Views: 6802

Answers (1)

akrun
akrun

Reputation: 886938

We can use a join on the 'id'

choice[rts, on = .(id)]

Upvotes: 2

Related Questions