n_dist2targ {COINr} | R Documentation |
A measure of the distance of each value of x
to a specified target which can be a high or low target depending on direction
. See details below.
n_dist2targ(x, targ, direction = 1, cap_max = FALSE)
x |
A numeric vector |
targ |
An target value |
direction |
Either 1 (default) or -1. In the former case, the indicator is assumed to be "positive" so that the target is at the higher end of the range. In the latter, the indicator is "negative" so that the target is typically at the low end of the range. |
cap_max |
If |
If direction = 1
, the formula is:
\frac{x - x_{min}}{x_{targ} - x_{min}}
else if direction = -1
:
\frac{x_{max} - x}{x_{max} - x_{targ}}
Values surpassing x_targ
in either case can be optionally capped at 1 if cap_max = TRUE
.
Numeric vector
x <- runif(20)
n_dist2targ(x, 0.8, cap_max = TRUE)