While following this tutorial on data.table
In the joining data.tables section they directly join X to another data.table DT and say that as X does not have a key, so its first column is used as its key.
but when I use the code,
X = data.table(c(“b”,“c”),foo=c(4,2))
1: b 4
2: c 2
DT[i = X]
it gives me an error->
[.data.table(DT, i = X) :
When i is a data.table (or character vector), x must be keyed (i.e. sorted, and, marked as sorted) so data.table knows which columns to join to and take advantage of x being sorted. Call setkey(x,…) first, see ?setkey.
So do we need to specify keys in each data.table before joining them or not?