1

I have a question regarding adding a column to a data.table based on info in another data.table.

This is how my data looks:

dt.1: One column with 1.9 million Product ID's
0771044445
0827229534
0827229534
0738700797
etc.

dt.2: Two columns with 7 million Product ID's + Categories
0842328327  Book
0842328327  Book
1577943082  DVD
Etc.

Now I want to create a column in dt.1 which adds the category by looking up this category in dt.2. All ID's of dt.1 are in dt.2.

I tried:

 dt.1[,group := ID %in% dt.2, by = dt.2$category] 

But I get the following error:

  Error in `[.data.frame`(dt.amazon.similar, , `:=`(group, asin %in% dt.amazon.reviews),  : unused argument (by = dt.amazon.reviews$group)
Saurabh Chauhan
  • 3,161
  • 2
  • 19
  • 46
Max
  • 31
  • 1
  • 6

1 Answers1

1

You could also use fast join syntax for inplace editing of dt1

dt.1[dt.2, on="Product ID", category:=category]
David Arenburg
  • 91,361
  • 17
  • 137
  • 196
Billy34
  • 1,777
  • 11
  • 11