Reputation: 421
I've seen examples of sorting a data table by one of its columns, but how do I sort a data table by the column of a different data table? For example if I have two data tables:
x <- data.table(ID=1:3,A=letters[3:1])
y <- data.table(ID=1:3,B=letters[1:3])
I want to sort x
based on the order of y$B
:
setorder(x,y$B)
Error in setorderv(x, cols, order, na.last) :
some columns are not in the data.table: $,y,B
How do I reference a col in y
when sorting x
?
Upvotes: 0
Views: 1840