aggregate.preferences {prefio} | R Documentation |
Aggregate Preferences
Description
Aggregate preferences
, returning an aggregated_preferences
object of
the unique preferences and their frequencies. The frequencies can be
accessed via the function frequencies()
.
Usage
## S3 method for class 'preferences'
aggregate(x, frequencies = NULL, ...)
as.aggregated_preferences(x, ...)
## S3 method for class 'aggregated_preferences'
x[i, j, ...]
frequencies(x)
Arguments
x |
A |
frequencies |
A vector of frequencies for preferences that have been previously aggregated. |
... |
Additional arguments, currently unused. |
i |
indices specifying preferences to extract. |
j |
indices specifying items to extract. |
as.aggregated_preferences |
if |
Value
A data frame of class aggregated_preferences
, with columns:
- preferences
A
preferences
object of the unique preferences- frequencies
The corresponding frequencies.
Methods are available for rbind()
and as.matrix()
.
Examples
# create a preferences object with duplicated preferences
R <- matrix(c(
1, 2, 0, 0,
0, 1, 2, 3,
2, 1, 1, 0,
1, 2, 0, 0,
2, 1, 1, 0,
1, 0, 3, 2
), nrow = 6, byrow = TRUE)
colnames(R) <- c("apple", "banana", "orange", "pear")
R <- as.preferences(R, format = "ranking")
# aggregate the preferences
A <- aggregate(R)
# Or pass `aggregate = TRUE` to `as.preferences`
A <- as.preferences(R, aggregate = TRUE)
# Subsetting applies to the preferences, e.g. first two unique preferences
A[1:2]
# (partial) preferences projected to items 2-4 only
A[, 2:4]
# Project preferences onto their hightest ranking
A[, 1, by.rank = TRUE]
# convert to a matrix
as.matrix(A)