Truncate preferences to a maximum number of ranks.
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. IfTRUE
, operates on bottom ranks.
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]