[R] How to check to see if a variable is within a range of another variable

Keith Jewell Keith.Jewell at campdenbri.co.uk
Thu Oct 2 15:06:35 CEST 2014


On 01/10/2014 23:54, Peter Alspach wrote:
> Tena koe Kate
>
> If kateDF is a data.frame with your data, then
>
> apply(kateDF, 1, function(x) isTRUE(all.equal(x[2], x[1], check.attributes = FALSE, tolerance=0.1)))
>
> comes close to (what I think) you want (but not to what you have illustrated in your 'eventual outcome').  Anyhow, it may be enough to allow you to get there.
>
> HTH ....
>
> Peter Alspach
>

I seem to need to specify all.equal(..., scale) to get correct values 
for some data/tolerances:
--------------
aDF <- data.frame(a = 1:10, b=10:1)

apply(aDF, 1, function(x)
   isTRUE(all.equal(x[2], x[1], check.attributes = FALSE, tolerance = 5, 
scale = 1))
   )
#  [1] FALSE FALSE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE FALSE FALSE
apply(aDF, 1, function(x)
   isTRUE(all.equal(x[2], x[1], check.attributes = FALSE, tolerance = 5))
)
#  [1]  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE FALSE FALSE
----------------------
I'm probably being stupid, but from reading ?all.equal I would have 
expected scale = 1 and the default scale = NULL to give identical 
results for the length one numerics being passed to all.equal.

Can anyone explain?

KJ



More information about the R-help mailing list