# 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)
Run the code above in your browser using DataLab