recodeQuick: recodeQuick to recode questionnaire data

Description Usage Arguments Value Examples

View source: R/qscales.R

Description

Questionnaire data usually contain only values ranging from 1 to 4 or 1 to 5. This function takes as input the items of a data frame that should be recoded (as numeric position or as names) and recodes these items. Unless missings are scored as NA and not, for example, as -99, the function will just reverse the values of the items.

Usage

1
recodeQuick(data, recode, valid.values = NULL)

Arguments

data

A data frame that contains only the values of the data frame.

recode

A numeric vector giving the poisitions of the items to recode or a character vector giving the names of the variables to recode.

valid.values

A vector containing the valid values of the questionnaire, i. e. the ones that should be recoded. Can be useful if missings are recoded as -99.

Value

The data frame with the recoded items.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
## eample 1
data <- data.frame(a = c(1, 2, -99), b = c(3, 4, NA))
recodeQuick(data, recode = "a", valid.values = c(1:4))

## example 2
data <- bigfive[grep(x = names(bigfive), pattern = "BFI_")]
data <- data[1:10, 1:10]
data[1, 6] <- -99 ## here, a missing is coded as -99.
recode <- c(6, 10)
recodeQuick(data, recode = c(6, 10), valid.values = c(1:4))

kthorstmann/quest documentation built on May 20, 2019, 7:05 p.m.