> > Is there an easy way to check whether a variable is within +/- 10%
> > range of another variable in R?
You could use
2*abs(A-B)/(A+B) < 0.1
which avoids an apply().
I've assumed you meant different by under 10% of the mean of the two, hence the
2/(A+B); if you meant 10% of something else, same kind of thing should work
with a different bottom line. For example if you meant less than 10% of the
smaller of the two, abs(A-B)/pmin(A, B) < 0.1 would do that
And if you want to check that they all comply,
all( 2*abs(A-B)/(A+B) < 0.1 )
will do that.
I liked Peter Langfelder's suggestion of all.equal, though; an interesting use
of a tolerance I've previously seen as there only to compensate for floating
point representation errors.
Steve E
*******************************************************************
This email and any attachments are confidential. Any use...{{dropped:8}}
______________________________________________
[email protected] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.