decode: Decode Orderings using a Key to Item Names

Description Usage Arguments Value Examples

View source: R/decode.R

Description

Decode orderings by replacing numeric or character coded values with item names.

Usage

1
decode(orderings, items, code = NULL)

Arguments

orderings

A data frame of coded orderings.

items

A data frame of the items in each ranking, or a vector of common items.

code

(Optional) a vector giving the key to the code. If missing, names(items) is used for a character code, while seq(items) is used for a numeric code.

Value

A data frame with the coded values replaced by the item names.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# orderings of up to 3 items coded as A, B, C
orderings <- data.frame(Rank1 = c("A", "B"),
                        Rank2 = c("C", "A"),
                        Rank3 = c("B", NA),
                        stringsAsFactors = FALSE)
items <- data.frame(A = c("banana", "apple"),
                    B = c("orange", "pear"),
                    C = c("apple", NA),
                    stringsAsFactors = FALSE)
decode(orderings, items)

# orderings with ties of up to 3 items, coded 1:3
orderings <- data.frame(Rank1 = c(1, 3),
                        Rank2 = I(list(c(2, 3), 2)),
                        Rank3 = c(NA, 1),
                        stringsAsFactors = FALSE)
items <- data.frame(A = c("banana", "apple"),
                    B = c("orange", "pear"),
                    C = c("apple", "orange"),
                    stringsAsFactors = FALSE)
decode(orderings, items)

# same items in each comparison
items <- c(A = "banana", B = "orange", C = "pear")
decode(orderings, items)

PlackettLuce documentation built on March 29, 2021, 5:06 p.m.