wide2long: Reshapes Paired Comparison Data

Description Usage Arguments Details Value Author(s) See Also Examples

View source: R/design.R

Description

This function reshapes a data frame that contains pair comparison data in 'wide' format into a data frame in 'long' format (see 'Details').

Usage

1
wide2long(data, paircomp, names=NULL, ...)

Arguments

data

a data frame in 'wide' format.

paircomp

a character vector specifying the columns from data that corresponds to a pair comparison.

names

a character vector of the same length as paircomp specifying the names (separated with a space) of the two objects that are compared in a pair comparison.

...

arguments to be passed to reshape.

Details

In the 'wide' format each row reflects a certain subject/judge and a column contains for example the results of a pair comparison or is a subject-specific covariate. In the 'long' format each row represents a single pair comparison.

Value

The reshaped data frame.

Author(s)

Giuseppe Casalicchio

See Also

reshape, design

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
data(CEMSwide)

# Define variable names containing the outcome of the comparisons
columns <- colnames(CEMSwide)[grep("V",colnames(CEMSwide))]

# Define names of the objects that are compared (shoud be separated with space)
# "London Paris" means that the first object is "London" and the second "Paris".
comparison <- c("London Paris", "London Milano", "Paris Milano", 
                "London St.Gallen", "Paris St.Gallen", 
                "Milano St.Gallen", "London Barcelona",
                "Paris Barcelona", "Milano Barcelona", 
                "St.Gallen Barcelona", "London Stockholm", 
                "Paris Stockholm", "Milano Stockholm",
                "St.Gallen Stockholm", "Barcelona Stockholm")

# Transform to 'long' format where v.names="Y" sets the name of 
# our response variable (see ?reshape)
CEMSlong <- wide2long(data=CEMSwide, paircomp=columns, names=comparison, v.names="Y")

head(CEMSlong)
head(CEMSwide)

ordBTL documentation built on May 2, 2019, 7:59 a.m.

Related to wide2long in ordBTL...