New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
better operators for interval-to-interval relations #6
Comments
It crossed my mind to implement these, however, here is why I did not in the 1st go round:
Out of these, point 3 is the most important, the other 2 are just stylistic/technical details. Do you have any suggestions on point 3? The symmetric cases could be shortened, e.g. |
|
I propose something like this:
|
OK, I will make a branch and start development with your proposal. |
@mgacc0 see here what I have so far in |
@mgacc0 I could test your function and it passed all the comparisons I came up with. The only issue right now is that it works for simple case but not yet vectorized (i.e. cannot accept matrices, lists because of the |
Firstly, a necessary correction: checking for empty intervals.
I would rename the For easier testing, I would recommend the testthat package:
For calling over dataframes, you could do something like this:
The notation for single vectors (intervals) is intuitive. Anyway, if you want to know how a function for data.frames would be:
|
Thanks. I just wanted to make the operators consistent with the I like your testing approach, but want to avoid too much dependencies. Even if I ignore |
This function seems to do the job: .intrval3 <-
function(interval1, interval2, type1, type2)
{
iv1 <- .get_intrval(interval1)
iv2 <- .get_intrval(interval2)
type1 <- match.arg(type1, c("[]", "[)", "(]", "()"))
type2 <- match.arg(type2, c("[]", "[)", "(]", "()"))
b1 <- ifelse(iv1$a < iv2$a, iv1$b, iv2$b)
a2 <- ifelse(iv1$a < iv2$a, iv2$a, iv1$a)
type1v <- ifelse(iv1$a < iv2$a, substr(type1, 2L, 2L), substr(type2, 2L, 2L))
type2v <- ifelse(iv1$a < iv2$a, substr(type2, 1L, 1L), substr(type1, 1L, 1L))
ifelse(type1v == "]" & type2v == "[",
b1 >= a2,
b1 > a2)
} The idea is similar to your proposal:
|
Could you have a look at ../pull/13 ? |
It would be really great to implement some new operators for interval-to-interval overlapping.
Instead of having the
%[o]%
operator for checking the overlapping between the closed intervals [a, b] and [x, y]expressed as
c(a, b) %[o]% c(x, y)
,it would be great having the
%[]o[]%
operatorexpressed as
c(a, b) %[]o[]% c(x, y)
.And then, for example:
Consequently, that would imply creating 32 operators (for all the combinations of open/closed endpoints):
%[]o[]%
%[]o[)%
%[]o(]%
%[]o()%
%[)o[]%
%[)o[)%
%[)o(]%
%[)o()%
The text was updated successfully, but these errors were encountered: