rank_trans: Transform ranking variables

Description Usage Arguments Details Examples

Description

This function is to transform ranking variables to comma-separated MA question

Usage

1

Arguments

vector

character vector

no_R

single integer

Details

Argument "no_R" indicates how many attributes the respondents should rank When codes of attributes are not consecutive, e.g. attribute 4 corresponds to code 8, instead of code 4, function replace_code() can be used to replace code 4 by code 8

Examples

1
2
3
4
5
6
7
8
9
#Create a ranking dataframe
ranking_df = data.frame(attribute1 = c("3", "3", "2", "2"),
attribute2 = c("1", "1", "1", "3"),
attribute3 = c("2", "2", "4", "1"),
attribute4 = c("4", "4", "3", "4"))
#Apply the function rowwise
apply(ranking_df, 1, rank_trans, no_R = 4)
#"2,3,1,4" "2,3,1,4" "2,1,4,3" "3,1,2,4";
#the first response means rank 1, the second means rank 2 and so on

momo3246/recode documentation built on Sept. 30, 2020, 2:14 p.m.