Skip to contents

Truncate preferences to a maximum number of ranks.

Usage

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

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.

Value

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

Examples

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