getQProps: Retreive and Modify Survey Question Properties

Description Usage Arguments Value Functions Character v. List levels Multiple questions and onlyMatches

Description

Functions to access or modify the information stored in the questionProperties attribute of SurveyQuestion objects. The most commonly used of these is setResponseLevels, which can rearrange or relabel the response options from multiple choice survey questions and identify ordinal survey scales (e.g., Likert), in order to generate appropriate population estimates in plots and summaries.

Usage

1
2
3
4
5
6
7
8
getQProps(x)

setQProps(x, questionProperties)

setResponseLevels(x, questionId, levels, var = c("responses", "subgroups"),
  ordinal = F, onlyMatches = F)

getResponseLevels(x, questionId, var = c("responses", "subgroups"))

Arguments

x

SurveyQuestion object.

questionProperties

questionProperties object.

questionId

Integer vector identifying one or more questions for retrieval or updating

levels

Character vector or named list desrcibing how to restructure the factor levels. See details.

var

Character identifying whether to update/retrieve the levels for the response or subgroup columns in x

ordinal

Logical indicating whether the levels should be treated as an ordered scale. Alters the way that population estimates are determined in plot and summary methods.

onlyMatches

Logical. Should levels only be updated for questions where each existing level matches with an item in levels? See details.

Value

For getQProps, a data frame wiht columns questionId (integer), question (factor), type (factor), subgroups (list), and responses (list). For setQProps and setResponseLevels, an updated SurveyQuestion object. For getResponseLevels, a character vector or list in the same format as levels above, optinally containing an "ordinal" attribute, or a list of such when questionId has length greater than 1.

@examples monkey <- data(exampleSurveyMonkey) # Rearrange levels, mark as ordinal, and omit "N/A" responses getResponseLevels(monkey, questionId = 1) newLevels <- c("TODO") monkey <- setResponseLevels(monkey, questionId = 1, levels = newLevels, ordinal = T) getResponseLevels(monkey, questionId = 1)

# Recode several scales in a survey into a unified scale newLevels <- list(Negative = c("TODO"), Neutral = c("TODO"), Positive = c("TODO")) monkey <- setResponseLevels(monkey, questionId = unique(monkey$questionId), levels = newLevels, onlyMatches = T)

Functions

Character v. List levels

When levels is provided as a character vector, it will be used as the levels argument of factor or ordered constructor. The values must match exactly to existing levels, but they can be specified in the order you want them to be displayed and you can omit levels that you want to be ommitted from plots and surveys (they will be treated as missing data). When levels is provided as a list, it will be provided as the value in a levels assignment. Each item in the list should be a named character vector of existing reponses, where its name specifies the replacement value. This allows you flexibilty to rename the responses and to unify scales from different questions into a consistent one. See examples and help files for factor and levels.

Multiple questions and onlyMatches

The questionId argument can be a vector to set or retrieve (as a list) levels for multiple questions within a SurveyQuestion object. With the onlyMatches option, you can apply level updates across many questions or the entire survey without having to pick out which questions the update applies to. When onlyMatches is TRUE, a check is performed for each question and the level update is only applied when all of the original responses can be matched to the values (when levels is a character vector) or item names (when levels is a list). When using this option, you cannot exclude specific reponses by omitting them from the new levels as this would prevent the new levels from matching with the question. See examples.


wmurphyrd/monkeywrangler documentation built on May 4, 2019, 9:46 a.m.