knitr::opts_chunk$set( collapse = TRUE, comment = "#>", fig.path = "README-" )
This vignette shows how to use qsurvey to download and work with responses collected with the Qualtrics survey platform. Before continuing you should have installed qsurvey; see the installation instructions.
library(qsurvey)
We'll start by downloading the responses to a survey called "Demographics."
(survey_id <- find_id("Demographics"))
responses()
sends a request to the Qualtrics API for our response data and
waits while the survey platform prepares the export. After downloading it,
responses()
returns the data.
demographics = responses(survey_id) class(demographics) dim(demographics)
By default, responses()
gives a table showing choice text or labels. This
means that if the respondent-facing answer choices for a question are "Low"
,
"Medium"
, and "High"
, the response data will contain these strings.
Alternatively, if argument use_labels = FALSE
, the response data will show
the choice ids "1"
, "2"
, and "3"
, or if choice recodes have been
configured, perhaps "-1"
, "0"
, and "1"
.
head(demographics$Q23) demographics_nolabels = responses(survey_id, use_labels = FALSE) head(demographics_nolabels$Q23)
As described in the documentation for response()
, other Qualtrics API
parameters that affect the format of
survey responses are available. For example, passing argument
seenUnansweredRecode = "99" to responses()
will show "99"
as the response to
unanswered questions instead of NA
, the default. See the Qualtrics
documentation if you need to customize
output from responses()
.
Let's take a look at the columns in the response data. The first five are survey
and respondent metadata. If they aren't useful to us, we can drop them with the
drop_meta()
function. We're left with actual survey responses and the eight
columns named DO-*
that give question display orders.
names(demographics) demographics <- drop_meta(demographics) names(demographics)
drop_sensitive()
and keep_questions()
are similar to drop_meta()
, but
target different column ranges.
By default, the response table's variable names are the descriptive export names
given to each question in the Qualtrics Control Panel. Let's instead name them
according to the unique identifiers of questions. We'll need the survey's design
to access these; we pass it and the table of responses to names_to_ids()
.
demo_design <- design(survey_id) demographics <- names_to_ids(demographics, demo_design) names(demographics)
ids_to_names()
does the reverse.
# FIXME: need to preserve suffixes for eg Q5_1, Q5_2 # demographics <- ids_to_names(demographics, demo_design) # names(demographics)
After downloading survey response data with responses()
, two sets of
convenience functions are available: one for dropping/keeping columns, and
another for renaming columns. If you have a question or suggestion, please open
a GitHub issue.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.