Description Usage Arguments Details Examples
This function is to transform ranking variables to comma-separated MA question
1 | rank_trans(vector, no_R)
|
vector |
character vector |
no_R |
single integer |
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
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
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.