Skip to content

sort = FALSE does't generate equivalent results with data.frame.merge #2574

@DavorJ

Description

@DavorJ

Here is sample/test code:

A <- data.frame(a=1:4)
AB <- data.frame(a=2:4, b=1)
merge(A,AB,all.x = TRUE,sort=FALSE)
  a  b
1 2  1
2 3  1
3 4  1
4 1 NA

A <- data.table::data.table(a=1:4)
AB <- data.table::data.table(a=2:4, b=1)
merge(A,AB,all.x = TRUE,sort=FALSE)
   a  b
1: 1 NA
2: 2  1
3: 3  1
4: 4  1

This can have profound effects. Merge depends on type of A and data.frame/data.table are interchangeable in many scenario's. Changing type of A can end up causing fireworks at unexpected places.

I don't know what the correct behavior should be, but I do think the results should be the same.

Metadata

Metadata

Assignees

Labels

documentationjoinsUse label:"non-equi joins" for rolling, overlapping, and non-equi joins

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions