group {prefio}R Documentation

Group Preferences

Description

Create an object of class grouped_preferences which associates a group index with an object of class preferences. This allows the preferences to be linked to covariates with group-specific values.

Usage

group(x, ...)

## S3 method for class 'preferences'
group(x, index, ...)

## S3 method for class 'grouped_preferences'
x[i, j, ...]

## S3 method for class 'grouped_preferences'
format(x, max = 2L, width = 20L, ...)

Arguments

x

A preferences object for group(); otherwise a grouped_preferences object.

...

Additional arguments passed on to as.preferences by grouped_preferences; unused by format.

index

A numeric vector or a factor with length equal to the number of preferences specifying the subject for each set.

i

Indices specifying groups to extract, may be any data type accepted by [.

j

Indices specifying items to extract. object, otherwise return a matrix/vector.

max

The maximum number of preferences to format per subject.

width

The maximum width in number of characters to format the preferences.

Value

An object of class grouped_preferences, which is a vector of of group IDs with the following attributes:

preferences

The preferences object.

index

An index matching each preference set to each group ID.

Examples


# ungrouped preferences (5 preference sets, 4 items)
R <- as.preferences(
  matrix(c(
    1, 2, 0, 0,
    0, 2, 1, 0,
    0, 0, 1, 2,
    2, 1, 0, 0,
    0, 1, 2, 3
  ), ncol = 4, byrow = TRUE),
  format = "ranking",
  item_names = LETTERS[1:4]
)
length(R)

# group preferences (first three in group 1, next two in group 2)
G <- group(R, c(1, 1, 1, 2, 2))
length(G)

## by default up to 2 preference sets are shown per group, "..." indicates if
## there are further preferences
G
print(G, max = 1)

## select preferences from group 1
G[1, ]

## exclude item 3 from preferences
G[, -3]

## Project preferences in all groups to their first preference
G[, 1, by.rank = TRUE]

## preferences from group 2, excluding item 3
## - note group 2 becomes the first (and only) group
G[2, -3]

# Group preferences by a factor
G <- group(R, factor(c("G1", "G1", "G1", "G2", "G2")))

G
print(G, max = 1)

## select preferences from group G1
G["G1"]


[Package prefio version 0.1.1 Index]