Some classification systems give a tolerance to some of their printed
thresholds: a value beyond the threshold but within the tolerance does not
fail the class, it attaches the soil to it imperfectly (the French
Referentiel pedologique 2008 calls this an imperfect attachment). within_tolerance() makes one
such comparison.
Usage
within_tolerance(value, threshold, direction = c("min", "max"), tol = 0)Arguments
- value
Numeric vector: the values compared (a factor or character vector is read by its labels).
- threshold
Numeric: the printed threshold, recycled.
- direction
"min"(the value must reach the threshold) or"max"(the value must not exceed it).- tol
Non-negative number: the tolerance, in the unit of the value, recycled.
NAorNULLreads as 0 (strict).
Details
For a minimum (direction = "min"), a value at or above the threshold
passes, a value below it by no more than tol is imperfect, and a
value further below fails. For a maximum ("max"), a value at or
below the threshold passes, a value above it by no more than tol is
imperfect, and a value further above fails. The edge of the tolerance band
is inclusive and read with a relative margin of 1e-9, so that 5.3 is within
0.2 of 5.5 despite the binary representation of decimals; the threshold
itself is read exactly. A tolerance of 0 makes the comparison strict (only
"pass" or "fail"). A missing value gives NA.
Examples
# organic carbon 6.5 g/100 g against a minimum of 8 with a tolerance of 2
within_tolerance(6.5, 8, "min", 2)
#> [1] "imperfect"
# horizons starting at 100, 130 and 150 cm against "within 120 cm",
# tolerance 20
within_tolerance(c(100, 130, 150), 120, "max", 20)
#> [1] "pass" "imperfect" "fail"
# a threshold with no tolerance is strict
within_tolerance(39, 40, "min", 0)
#> [1] "fail"
