Learn R Programming

cata (version 0.1.0.27)

topc: Apply top-c choices coding to a vector of scale data from a respondent

Description

Apply top-c choices coding to a vector of scale data from a respondent

Usage

topc(x, c = 2, coding = "B")

Value

matrix X with top-k coding applied

Arguments

x

input matrix

c

number of top choices considered to be 'success'; other choices are considered to be 'failure' and are coded 0

coding

"B" (default) codes all successes as 1; "N" codes all successes with their numeric coding

Author

J.C. Castura

References

Castura, J.C., Meyners, M., Pohjanheimo, T., Varela, P., & Næs, T. (2023). An approach for clustering consumers by their top-box and top-choice responses. Journal of Sensory Studies, e12860. tools:::Rd_expr_doi("10.1111/joss.12860")

Examples

Run this code
# Generate some data
set.seed(123)
X <- matrix(sample(1:9, 100, replace = TRUE), nrow = 5)

# apply top-2 choice (T2C) coding
apply(X, 1, topc)

Run the code above in your browser using DataLab