Description Usage Arguments Value Functions Character v. List levels Multiple questions and onlyMatches
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.
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"))
|
x |
|
questionProperties |
|
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 |
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 |
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)
setQProps
: Replaces the questionProperties
attribute of
x
. No validity checks are performed and no propagation of changes
into the SurveyQuestion
data occurs, so the use of this function to
modify question properties discouraged. One normal use is restoring the
questionProperties
attribute after utilizing functions such as
mutate
which cause attributes to be lost, having first
preserved the questionProperties
by storing the result of
getQProps
in a variable.
setResponseLevels
: The SurveyMonkey XLS export contains limited
information about the original response options. For single repsonse
questions, options that were never selected will be omitted and their order
will not be retained. For both single and multiple response questions, any
"weighting" or ordinal ranking of options is never retained. The plot and
summary methods in this package can make use of that information, but it
needs to be restored with setResponseLevels
. This function is
designed to be versatile to make that process as simple as possible.
Changes made via setResponseLevels
do not alter the underlying data
in the SurveyQuestion
object; instead they alter how that data is
provided when other methods use extractQuestion
to access it.
getResponseLevels
: Used to retreive the currently specified levels for
responses or subgroups for one or more questions. The returned object is of
the same structure as the levels
argument to setResponseLevels
and will have an attribute "ordinal" with a logical value or TRUE if the
levels represent those of an ordered factor.
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
.
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.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.