Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
721 views
in Technique[技术] by (71.8m points)

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.

question from:https://stackoverflow.com/questions/65869067/data-table-in-r-the-columns-to-join-by-must-be-specified-using-on-argument

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

We can use a join on the 'id'

choice[rts, on = .(id)]

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...