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 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]

# (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)

[Package prefio version 0.1.1 Index]