base_pref_macros | R Documentation |
In addition to the base preferences, rPref offers some macros to define preferences where a given interval or point is preferred.
around(expr, center, df = NULL) between(expr, left, right, df = NULL) pos(expr, pos_value, df = NULL) layered(expr, ..., df = NULL)
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 |
between(expr, left, right)
Those tuples are preferred where 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)
Same as between(expr, center, center)
.
pos(expr, pos_value)
Those tuples are preferred, where expr
evaluates
to a value which is contained in pos_value
.
layered(expr, layer1, layer2, ..., layerN)
For the most preferred tuples 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.
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.
# 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))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.