Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

r

data.table

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.

like image 672
Alireza Izadimehr Avatar asked Nov 18 '25 23:11

Alireza Izadimehr


1 Answers

We can use a join on the 'id'

choice[rts, on = .(id)]
like image 160
akrun Avatar answered Nov 21 '25 19:11

akrun



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!