Skip to contents

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 preferences
aggregate(x, frequencies = NULL, ...)

as.aggregated_preferences(x, ...)

# S3 method for aggregated_preferences
[(x, i, j, ...)

frequencies(x)

Arguments

x

A preferences object for aggregate(); an object that can be coerced to an aggregated_preferences object for as.aggregated_preferences(), otherwise an aggregated_preferences object.

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 TRUE create an aggregated_preferences object from the indexed preferences Otherwise index the underlying matrix of ranks and return in a data frame with the corresponding frequencies.

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]
#>                        preferences frequencies
#> 1 [orange = pear > apple > banana]           2
#> 2 [pear > banana = orange > apple]           2

# (partial) preferences projected to items 2-4 only
A[, 2:4]
#>                preferences frequencies
#> 1 [orange = pear > banana]           2
#> 2 [pear > banana = orange]           2
#> 3 [banana > orange > pear]           1
#> 4 [banana > pear > orange]           1

# Project preferences onto their hightest ranking
A[, 1, by.rank = TRUE]
#>       preferences frequencies
#> 1 [orange = pear]           2
#> 2          [pear]           2
#> 3         [apple]           1
#> 4        [banana]           1

# convert to a matrix
as.matrix(A)
#>      apple banana orange pear frequencies
#> [1,]     2      3      1    1           2
#> [2,]     3      2      2    1           2
#> [3,]     1      2      3    4           1
#> [4,]     2      1      4    3           1