Learn R Programming

prefio (version 0.2.0)

pref_trunc: Truncate preferences to a maximum number of ranks.

Description

Truncate preferences to a maximum number of ranks.

Usage

pref_trunc(x, n = 1L, bottom = FALSE)

Value

A vector of preferences with each selection truncated according to the parameters.

Arguments

x

A vector of preferences.

n

The maximum number of ranks to include (positive) or number of ranks to drop (negative). Must be an integer.

bottom

If FALSE (default), operates on top ranks. If TRUE, operates on bottom ranks.

Examples

Run this code
# Keep only the top 2 ranks
pref_trunc(preferences(c("a > b > c > d", "b > c > a")), n = 2)
# Keep only the bottom 2 ranks
pref_trunc(preferences(c("a > b > c > d", "b > c > a")), n = 2, bottom = TRUE)
# Drop the bottom 2 ranks (keep top ranks)
pref_trunc(preferences(c("a > b > c > d", "b > c > a")), n = -2)
# Drop the top 2 ranks (keep bottom ranks)
pref_trunc(preferences(c("a > b > c > d", "b > c > a")), n = -2, bottom = TRUE)

Run the code above in your browser using DataLab