R: Useful Base Preference Macros

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 `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.
`center` | Preferred numerical value for `around`.
`df` | (optional) Data frame for partial evaluation and association of preference and data set. See `base_pref` for details.
`left` | Lower limit (numerical) of the preferred interval for `between`.
`right` | Upper limit (numerical) of the preferred interval for `between`.
`pos_value` | A vector containing the preferred values for a `pos` preference. It has to be of the same type (numeric, logical, character, ...) as `expr`.
`...` | Layers (sets) for a `layered` preference. Each parameter corresponds to a layer and the first one characterizes the most preferred values.

### Definition of the Preference Macros

`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.

### Examples

    # 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))

[Package rPref version 1.3 Index]