You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
data.table internally uses the "sorted" attribute for storing keys. Setting these values own your own will result in a data.table that is actually not sorted, but believes it is, hence, the wrong result.
Note that you specify that tables are sorted by ID but they aren't, at least as long as you use character columns... "100" < "99" is TRUE, in case you missed that.
t1<- structure(list(ID= c("100","99"))
, sorted="ID"# <<-------- NEW
, class= c("data.table", "data.frame")
)
t2<- structure(list(ID="100", x=1)
, sorted="ID"# <<-------- NEW
, class= c("data.table","data.frame")
)
merge(t1,t2,by="ID",all=TRUE)
#Key: <ID># ID x# <char> <num>#1: 100 1#2: 99 NA
So if you set sorted attribute according to the real order (note I fixed order of "100" and "99"), merge works fine. Anyway, the only supported way to set sorted attribute is to use setkey, setkeyv, [, keyby=].
I don't know if it is really a bug or an intentended beahaviour, but to me it's a bug !
I have two data.table t1 and t2 like this
The merge is OK :
But If I have the same data.table with a sorted attribute (resulting from another merge for instance), the table looks the same :
But the merge is now erroneous :
Do you confirm it's a bug ?
Kind regards !
Dominique
The text was updated successfully, but these errors were encountered: