base_pref_macros {rPref} | R Documentation |
Useful Base Preference Macros
Description
In addition to the base preferences, rPref offers some macros to define preferences where a given interval or point is preferred.
Usage
around(expr, center, df = NULL)
between(expr, left, right, df = NULL)
pos(expr, pos_value, df = NULL)
layered(expr, ..., df = NULL)
Arguments
expr |
A numerical expression (for |
center |
Preferred numerical value for |
df |
(optional) Data frame for partial evaluation and association of preference and data set.
See |
left |
Lower limit (numerical) of the preferred interval for |
right |
Upper limit (numerical) of the preferred interval for |
pos_value |
A vector containing the preferred values for a |
... |
Layers (sets) for a |
Definition of the Preference Macros
between(expr, left, right)
Those tuples are preferred where
expr
evaluates to a value betweenleft
andright
. For values not in this interval, the values nearest to the interval are preferred.around(expr, center)
Same as
between(expr, center, center)
.pos(expr, pos_value)
Those tuples are preferred, where
expr
evaluates to a value which is contained inpos_value
.layered(expr, layer1, layer2, ..., layerN)
For the most preferred tuples
expr
must evaluate to a value inlayer1
. The second-best tuples are those whereexpr
evaluates to a value inlayer2
and so forth. Values occurring in none of the layers are considered worse than those inlayerN
. Technically, this is realized by a prioritization chain (lexicographical order) oftrue
preferences.
Note that only the argument 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.
Examples
# Search for cars where mpg is near to 25.
psel(mtcars, around(mpg, 25))
# Consider cyl = 2 and cyl = 4 as equally good, while cyl = 6 is worse.
psel(mtcars, layered(cyl, c(2, 4), 6))