Unexpected result from non-equi-join
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 35/100
Research direction
Reproduce the two non-equi-join examples from the issue with the supplied p1 and p2 data, then compare their subset results with the in-place modification result. Trace the non-equi-join subset behavior and determine whether the observed rows are intended; done means the behavior is clarified or corrected with coverage for this example.
Written by the indexing model from the issue text.
Description
Suppose we have the following data.tables:
library(data.table)
p1 <- data.table(
symbol = c("A", "A", "A", "B", "B", "B"),
date = c(1L, 2L, 3L, 1L, 2L, 3L)
)
p2 <- data.table(
symbol = c("A", "A", "B"),
start_date = c(1L, 2L, 1L),
end_date = c(1L, 3L, 2L),
id = 1:3
)
> p1
symbol date
<char> <int>
1: A 1
2: A 2
3: A 3
4: B 1
5: B 2
6: B 3
> p2
symbol start_date end_date id
<char> <int> <int> <int>
1: A 1 1 1
2: A 2 3 2
3: B 1 2 3
In-place modification with non-equi-join works as expected:
p1[p2, id := id, on = .(symbol, date >= start_date, date <= end_date)]
> p1
symbol date id
<char> <int> <int>
1: A 1 1
2: A 2 2
3: A 3 2
4: B 1 3
5: B 2 3
6: B 3 NA
However, using the non-equi-join syntax to subset p1 with p2 does not seem to work consistently:
p1[p2, .(symbol, date), on = .(symbol, date >= start_date, date <= end_date)]
symbol date
<char> <int>
1: A 1
2: A 2
3: A 2
4: B 1
5: B 1
or
p1[p2, on = .(symbol, date >= start_date, date <= end_date)]
symbol date id date.1 i.id
<char> <int> <int> <int> <int>
1: A 1 1 1 1
2: A 2 2 3 2
3: A 2 2 3 2
4: B 1 3 2 3
5: B 1 3 2 3
But I expect the result to be like
p2 <- p1[!is.na(id)]
p2
symbol date id
<char> <int> <int>
1: A 1 1
2: A 2 2
3: A 3 2
4: B 1 3
5: B 2 3
I wonder if this is a known behavior? Or is there an explanation why it is not the expected result like above? Am I missing something about the definition of the non-equi-join?
- Dominant language
- R
- Stars
- 3.9k
- Forks
- 1.1k
- Avg merge
- 14h 4m
- Merged PRs (30d)
- 4
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from Rdatatable/data.table
-
as.data.table() recurses without end on a survival::Surv object (or any data.frame carrying one) Open
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
Rdatatable/data.table#7887 ·
-
consistency tests
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
Rdatatable/data.table#7853 · 3 comments ·
-
internals
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
Rdatatable/data.table#6938 · 1 comment ·
-
encoding fread
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
Rdatatable/data.table#5179 · 8 comments ·
-
documentation programming
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
Rdatatable/data.table#3199 · 3 comments ·
All issues in Rdatatable/data.table
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
r-lib/pkgdepends#485 · 3 comments ·
-
Difficulty 1/5 Under an hour Newbie friendliness 92/100
-
beginners blocker
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
enviPathR OpenBuild Error Build OK Build Warning policies-accepted pre-review precheck-passed
Difficulty 1/5 Under an hour Newbie friendliness 84/100
Bioconductor/BiocContributions#207 · 6 comments ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
datacarpentry/semester-biology#1255 ·