around(expr, center, df = NULL)
between(expr, left, right, df = NULL)
pos(expr, pos_value, df = NULL)
layered(expr, ..., df = NULL)around and between)
or an arbitrary expression (for pos and layered).
The objective are those tuples where expr evaluates to a value within the preferred interval, layer, etc.
Regarding attributes, functions and variables, the same requirements as for base_pref apply.around.base_pref for details.between.between.pos preference.
It has to be of the same type (numeric, logical, character, ...) as expr.layered preference. Each parameter corresponds to a layer
and the first one characterizes the most preferred values.between(expr, left, right)expr evaluates
to a value between left and right.
For values not in this interval, the values nearest to the interval are preferred.around(expr, center)between(expr, center, center).pos(expr, pos_value)expr evaluates
to a value which is contained in pos_value.layered(expr, layer1, layer2, ..., layerN)expr
must evaluate to a value in layer1.
The second-best tuples are those where expr evaluates to a value in layer2 and so forth.
Values occurring in none of the layers are considered worse than those in layerN.
Technically, this is realized by a prioritization chain (lexicographical order)
of true preferences.expr may contain columns from the data frame,
all other variables must evaluate to explicit values.
For example around(mpg, mean(mpg)) is not allowed. In this case, one can use
around(mpg, mean(mtcars$mpg)) instead. Or alternatively, without using the base preference macros,
low(abs(mpg - mean(mpg))) does the same. There, the actual mean value of mpg is calculated
just when the preference selection via psel is called.# search for cars where mpg is near to 25
psel(mtcars, around(mpg, 25))
# cyl = 2 and cyl = 4 are equally good, cyl = 6 is worse
psel(mtcars, layered(cyl, c(2, 4), 6))
Run the code above in your browser using DataLab