labelling: Attach textual label to pre-coded data

Description Usage Arguments Details Examples

Description

This function is to attach textual label to numeric data by using a code spec

Usage

1
labelling(data, code_spec)

Arguments

data

dataframe

code_spec

dataframe with 3 columns: first one being "varible name", second one being "code", and thrid one being "label"

Details

This function would show output covering 3 cases: 1) The variable being processed is not included in code spec, in which case the variable would be left unchanged; 2) The variable being processed is a SA question, and 3) The variable being process is a MA question

Note that if the code is not specified in code spec, the cell containing that code would be showing NA, rather than displaying its original code

Use xlsx::write.xlsx() to export, with the argument showNA being set as FALSE.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
data <- data.frame(vQ1=c(1, 3, 4, 99),
                   vQ2=c("1,2", "3,4", "5,3", "1,2,99"),
                   vQ3=c(NA, NA, NA, NA),
                   vQ4=c(NA, 1, 3, "2,4"),
                   vQ5=c(1,2,3,4), stringsAsFactors=FALSE)##Populate the "data" dataframe
code_spec <- data.frame(variable_name=rep(c("vQ1", "vQ2", "vQ3", "vQ4"), each=5),
                        code=rep(c(1,2,3,4,5), times=4),
                        label=rep(c("1. Ricoh",
                        "2. Fuji Xerox",
                        "3. Canon",
                        "4. Konica Minolta",
                        "5. Sharp"), times=4))##Populate the "code_spec" dataframe

labelling(data, code_spec)

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