Skip to content
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

Questionable Results #17

Open
brichard1638 opened this issue Mar 3, 2024 · 5 comments
Open

Questionable Results #17

brichard1638 opened this issue Mar 3, 2024 · 5 comments

Comments

@brichard1638
Copy link

brichard1638 commented Mar 3, 2024

This issue concerns the output provided by the in.range function. In the latest version of quickcode, version 0.7, there appears to be an inconsistency in the output based on two equally defined functional configurations.

The proposed error is reproduced below.

For example, the following in.range code yields the following output with all TRUE values:
library(quickcode)
in.range(50:60, range.vec = c(55,33,22,56,75,213,120))
[1] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE

The code syntax reconfigures the in.range function where the output should be the same - but it's not:
x = c(55,33,22,56,75,213,120)
in.range(x, range.min = 50, range.max = 60)
[1] TRUE FALSE FALSE TRUE FALSE FALSE FALSE

Since there are 11 values returned in the first example and only 7 in the second example, it begs the question as to how the first example is being evaluated against the range.vec argument. How is the function being evaluated where all values returned are TRUE?

@oobianom
Copy link
Owner

oobianom commented Mar 5, 2024

I see your question Brice, perhaps the documentation needs to be revised?

in.range( value, range.min, range.max, range.vec = NULL, closest = FALSE, rm.na = FALSE )

So the in.range is simply looking to see if "value" exists within the range.

The range for which "value" should be test can be either two numbers, a minimum (range.min) and a maximum (range.max).

Now, depending on the kind of data you are working with, this means that you first have to compute the range.min and range.max, before using the function to test if "value" is in that range.
Well, the current function provides a second option to save you the step of computing the range.min and range.max, it is the range.vec . Therefore, range.vec is an alternative means to specify the range for which "value" should be tested. When range.vec is specified, the function simply uses range(range.vec) to compute range.min and range.max before proceeding to test if "value" is within that range.

Let me know if it makes sense now, and what you think Brice.

@brichard1638
Copy link
Author

brichard1638 commented Mar 5, 2024 via email

@oobianom
Copy link
Owner

oobianom commented Mar 6, 2024

Hi Brice, okay let me explain.

Function call:
in.range(50:60, range.vec = c(55,33,22,56,75,213,120))

Behavior:
a = sort(c(55,33,22,56,75,213,120))
range.min = a[1]
range.max = a[7]

Now, the function will test this -
sample_to_test = c(50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60) # same thing as 50:60

For each of the numbers in the vector sample_to_test, the function will test if the number is between range.min and range.max

It will return result for each of the 11 values in sample_to_test, that's why you see
[1] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE

Again, may be the solution here will be to improve the documentation so that it is more clear. What do you think?

@brichard1638
Copy link
Author

brichard1638 commented Mar 7, 2024

I'm still confused. If the sample_to_test is 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60 and the min range is 55 a[1] while the max range is 120 a[7], then 50 through 54 should be FALSE not TRUE as none of these values are within a range of 55-120. Another question I have is that 120 is not the largest value in the range - it's actually 213 at a[6]. ???

Am I missing something here?

@oobianom
Copy link
Owner

oobianom commented Jun 1, 2024

Resolving this issue will also be part of the next release

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants