Title: | Tools to Work with Survey Data |
---|---|
Description: | Data obtained from surveys contains information not only about the survey responses, but also the survey metadata, e.g. the original survey questions and the answer options. The 'surveydata' package makes it easy to keep track of this metadata, and to easily extract columns with specific questions. |
Authors: | Andrie de Vries [aut, cre, cph], Evan Odell [ctb] |
Maintainer: | Andrie de Vries <[email protected]> |
License: | GPL-2|GPL-3 |
Version: | 0.2.7 |
Built: | 2024-11-02 02:56:47 UTC |
Source: | https://github.com/andrie/surveydata |
Tools, classes and methods to manipulate survey data.
Surveydata objects have been designed to function with SPSS export data, i.e. the result of an SPSS import, foreign::read.spss()
. This type of data is contained in a data.frame, with information about the questionnaire text in the variable.labels
attribute. Surveydata objects keep track of the variable labels, by offering methods for renaming, subsetting, etc.
Coercion functions:
To access and modify attributes:
To subset or merge surveydata objects:
To extract question text from varlabels:
To fix common encoding problems:
To clean data:
remove_dont_know()
to remove "Don't know" responses
remove_all_dont_know()
to remove "Don't know" responses from all questions
fix_levels_01()
to fix level formatting of all question with Yes/No type answers
Miscellaneous tools:
dropout()
to determine questions where respondents drop out
Andrie de Vries [email protected]
library(surveydata) # Create surveydata object sdat <- data.frame( id = 1:4, Q1 = c("Yes", "No", "Yes", "Yes"), Q4_1 = c(1, 2, 1, 2), Q4_2 = c(3, 4, 4, 3), Q4_3 = c(5, 5, 6, 6), Q10 = factor(c("Male", "Female", "Female", "Male")), crossbreak = c("A", "A", "B", "B"), weight = c(0.9, 1.1, 0.8, 1.2) ) varlabels(sdat) <- c( "RespID", "Question 1", "Question 4: red", "Question 4: green", "Question 4: blue", "Question 10", "crossbreak", "weight" ) sv <- as.surveydata(sdat, renameVarlabels = TRUE) # Extract specific questions sv[, "Q1"] sv[, "Q4"] # Query attributes varlabels(sv) pattern(sv) # Find unique questions questions(sv) which.q(sv, "Q1") which.q(sv, "Q4") # Find question text question_text(sv, "Q1") question_text(sv, "Q4") question_text_common(sv, "Q4") question_text_unique(sv, "Q4") # Basic operations on a surveydata object, illustrated with the example dataset membersurvey class(membersurvey) questions(membersurvey) which.q(membersurvey, "Q1") which.q(membersurvey, "Q3") which.q(membersurvey, c("Q1", "Q3")) question_text(membersurvey, "Q3") question_text_unique(membersurvey, "Q3") question_text_common(membersurvey, "Q3") # Extracting columns from a surveydata object head(membersurvey[, "Q1"]) head(membersurvey["Q1"]) head(membersurvey[, "Q3"]) head(membersurvey[, c("Q1", "Q3")]) # Note that the result is always a surveydata object, even if only one column is extracted head(membersurvey[, "id"]) str(membersurvey[, "id"])
library(surveydata) # Create surveydata object sdat <- data.frame( id = 1:4, Q1 = c("Yes", "No", "Yes", "Yes"), Q4_1 = c(1, 2, 1, 2), Q4_2 = c(3, 4, 4, 3), Q4_3 = c(5, 5, 6, 6), Q10 = factor(c("Male", "Female", "Female", "Male")), crossbreak = c("A", "A", "B", "B"), weight = c(0.9, 1.1, 0.8, 1.2) ) varlabels(sdat) <- c( "RespID", "Question 1", "Question 4: red", "Question 4: green", "Question 4: blue", "Question 10", "crossbreak", "weight" ) sv <- as.surveydata(sdat, renameVarlabels = TRUE) # Extract specific questions sv[, "Q1"] sv[, "Q4"] # Query attributes varlabels(sv) pattern(sv) # Find unique questions questions(sv) which.q(sv, "Q1") which.q(sv, "Q4") # Find question text question_text(sv, "Q1") question_text(sv, "Q4") question_text_common(sv, "Q4") question_text_unique(sv, "Q4") # Basic operations on a surveydata object, illustrated with the example dataset membersurvey class(membersurvey) questions(membersurvey) which.q(membersurvey, "Q1") which.q(membersurvey, "Q3") which.q(membersurvey, c("Q1", "Q3")) question_text(membersurvey, "Q3") question_text_unique(membersurvey, "Q3") question_text_common(membersurvey, "Q3") # Extracting columns from a surveydata object head(membersurvey[, "Q1"]) head(membersurvey["Q1"]) head(membersurvey[, "Q3"]) head(membersurvey[, c("Q1", "Q3")]) # Note that the result is always a surveydata object, even if only one column is extracted head(membersurvey[, "id"]) str(membersurvey[, "id"])
DT
package.Converts free format question text to datatable using the DT
package.
as_opentext_datatable(data, q)
as_opentext_datatable(data, q)
data |
surveydata object |
q |
Question |
Other open text functions:
print_opentext()
as_opentext_datatable(membersurvey, "Q33")
as_opentext_datatable(membersurvey, "Q33")
Coerces surveydata object to data.frame.
## S3 method for class 'surveydata' as.data.frame(x, ..., rm.pattern = FALSE)
## S3 method for class 'surveydata' as.data.frame(x, ..., rm.pattern = FALSE)
x |
Surveydata object to coerce to class data.frame |
... |
ignored |
rm.pattern |
If TRUE removes |
Methods for creating surveydata
objects, testing for class, and coercion from other objects.
as.surveydata( x, sep = "_", exclude = "other", ptn = pattern(x), defaultPtn = list(sep = sep, exclude = exclude), renameVarlabels = FALSE ) un_surveydata(x)
as.surveydata( x, sep = "_", exclude = "other", ptn = pattern(x), defaultPtn = list(sep = sep, exclude = exclude), renameVarlabels = FALSE ) un_surveydata(x)
x |
Object to coerce to surveydata |
sep |
Separator between question and sub-question names |
exclude |
Excludes from pattern search |
ptn |
A list with two elements, |
defaultPtn |
The default for |
renameVarlabels |
If TRUE, turns variable.labels attribute into a named vector, using |
The functionun_surveydata()
removes the surveydata
class from the object, leaving intact the other classes, e.g. data.frame
or tibble
surveydata-package, is.surveydata()
library(surveydata) # Create surveydata object sdat <- data.frame( id = 1:4, Q1 = c("Yes", "No", "Yes", "Yes"), Q4_1 = c(1, 2, 1, 2), Q4_2 = c(3, 4, 4, 3), Q4_3 = c(5, 5, 6, 6), Q10 = factor(c("Male", "Female", "Female", "Male")), crossbreak = c("A", "A", "B", "B"), weight = c(0.9, 1.1, 0.8, 1.2) ) varlabels(sdat) <- c( "RespID", "Question 1", "Question 4: red", "Question 4: green", "Question 4: blue", "Question 10", "crossbreak", "weight" ) sv <- as.surveydata(sdat, renameVarlabels = TRUE) # Extract specific questions sv[, "Q1"] sv[, "Q4"] # Query attributes varlabels(sv) pattern(sv) # Find unique questions questions(sv) which.q(sv, "Q1") which.q(sv, "Q4") # Find question text question_text(sv, "Q1") question_text(sv, "Q4") question_text_common(sv, "Q4") question_text_unique(sv, "Q4") # Basic operations on a surveydata object, illustrated with the example dataset membersurvey class(membersurvey) questions(membersurvey) which.q(membersurvey, "Q1") which.q(membersurvey, "Q3") which.q(membersurvey, c("Q1", "Q3")) question_text(membersurvey, "Q3") question_text_unique(membersurvey, "Q3") question_text_common(membersurvey, "Q3") # Extracting columns from a surveydata object head(membersurvey[, "Q1"]) head(membersurvey["Q1"]) head(membersurvey[, "Q3"]) head(membersurvey[, c("Q1", "Q3")]) # Note that the result is always a surveydata object, even if only one column is extracted head(membersurvey[, "id"]) str(membersurvey[, "id"])
library(surveydata) # Create surveydata object sdat <- data.frame( id = 1:4, Q1 = c("Yes", "No", "Yes", "Yes"), Q4_1 = c(1, 2, 1, 2), Q4_2 = c(3, 4, 4, 3), Q4_3 = c(5, 5, 6, 6), Q10 = factor(c("Male", "Female", "Female", "Male")), crossbreak = c("A", "A", "B", "B"), weight = c(0.9, 1.1, 0.8, 1.2) ) varlabels(sdat) <- c( "RespID", "Question 1", "Question 4: red", "Question 4: green", "Question 4: blue", "Question 10", "crossbreak", "weight" ) sv <- as.surveydata(sdat, renameVarlabels = TRUE) # Extract specific questions sv[, "Q1"] sv[, "Q4"] # Query attributes varlabels(sv) pattern(sv) # Find unique questions questions(sv) which.q(sv, "Q1") which.q(sv, "Q4") # Find question text question_text(sv, "Q1") question_text(sv, "Q4") question_text_common(sv, "Q4") question_text_unique(sv, "Q4") # Basic operations on a surveydata object, illustrated with the example dataset membersurvey class(membersurvey) questions(membersurvey) which.q(membersurvey, "Q1") which.q(membersurvey, "Q3") which.q(membersurvey, c("Q1", "Q3")) question_text(membersurvey, "Q3") question_text_unique(membersurvey, "Q3") question_text_common(membersurvey, "Q3") # Extracting columns from a surveydata object head(membersurvey[, "Q1"]) head(membersurvey["Q1"]) head(membersurvey[, "Q3"]) head(membersurvey[, c("Q1", "Q3")]) # Note that the result is always a surveydata object, even if only one column is extracted head(membersurvey[, "id"]) str(membersurvey[, "id"])
Combines surveydata object by columns.
## S3 method for class 'surveydata' cbind(..., deparse.level = 1)
## S3 method for class 'surveydata' cbind(..., deparse.level = 1)
... |
surveydata objects |
deparse.level |
ignored |
The number of respondents for each question is calculated as the length of the vector, after omitting NA values.
dropout(x, summary = TRUE)
dropout(x, summary = TRUE)
x |
surveydata object, list or data.frame |
summary |
If TRUE, returns a shortened vector that contains only the points where respondents drop out. Otherwise, returns the number of respondents for each question. |
Named numeric vector of respondent counts
dropout(membersurvey[-(127:128)])
dropout(membersurvey[-(127:128)])
Conversion of character vector to integer vector. The encoding of the character vector can be specified but defaults to the current locale.
encToInt(x, encoding = localeToCharset())
encToInt(x, encoding = localeToCharset())
x |
Character vector |
encoding |
A character string describing the encoding of x. Defaults to the current locale. See also |
An integer vector
Other Functions to clean data:
fix_common_encoding_problems()
,
fix_levels_01_spss()
,
has_dont_know()
,
intToEnc()
,
leveltest
,
remove_all_dont_know()
,
remove_dont_know()
encToInt("\xfa")
encToInt("\xfa")
This function tries to resolve typical encoding problems when importing web data on Windows. Typical problems occur with pound and emdash (-), especially when these originated in MS-Word.
fix_common_encoding_problems(x, encoding = localeToCharset())
fix_common_encoding_problems(x, encoding = localeToCharset())
x |
A character vector |
encoding |
A character string describing the encoding of x. Defaults to the current locale. See also |
Other Functions to clean data:
encToInt()
,
fix_levels_01_spss()
,
has_dont_know()
,
intToEnc()
,
leveltest
,
remove_all_dont_know()
,
remove_dont_know()
Fix level formatting of all question with Yes/No type answers.
fix_levels_01_spss(dat) fix_levels_01_r(dat) fix_levels_01(dat, origin = c("R", "SPSS"))
fix_levels_01_spss(dat) fix_levels_01_r(dat) fix_levels_01(dat, origin = c("R", "SPSS"))
dat |
surveydata object |
origin |
Either |
Other Functions to clean data:
encToInt()
,
fix_common_encoding_problems()
,
has_dont_know()
,
intToEnc()
,
leveltest
,
remove_all_dont_know()
,
remove_dont_know()
Returns TRUE if x contains any instances of dk
has_dont_know(x, dk = "Don't Know")
has_dont_know(x, dk = "Don't Know")
x |
Character vector or factor |
dk |
Character vector, containing search terms, e.g. |
TRUE or FALSE
Other Functions to clean data:
encToInt()
,
fix_common_encoding_problems()
,
fix_levels_01_spss()
,
intToEnc()
,
leveltest
,
remove_all_dont_know()
,
remove_dont_know()
Conversion of integer vector to character vector. The encoding of the character vector can be specified but defaults to the current locale.
intToEnc(x, encoding = localeToCharset())
intToEnc(x, encoding = localeToCharset())
x |
Integer vector |
encoding |
A character string describing the encoding of x. Defaults to the current locale. See also |
A character vector
Other Functions to clean data:
encToInt()
,
fix_common_encoding_problems()
,
fix_levels_01_spss()
,
has_dont_know()
,
leveltest
,
remove_all_dont_know()
,
remove_dont_know()
intToEnc(8212)
intToEnc(8212)
Tests whether an object is of class surveydata.
is.surveydata(x)
is.surveydata(x)
x |
Object to check for being of class surveydata |
This is useful to clean only some columns in a list (or data.frame
or surveydata
object). This is a simple wrapper around lapply()
where only the named elements are changed.
lapply_names(x, names, FUN, ...)
lapply_names(x, names, FUN, ...)
x |
list |
names |
character vector identifying which elements of the list to apply FUN |
FUN |
function to apply. |
... |
additional arguments passed to |
Other Tools:
question_order()
Fix level formatting of all question with Yes/No type answers.
leveltest_spss(x) leveltest_r(x)
leveltest_spss(x) leveltest_r(x)
x |
surveydata object |
Other Functions to clean data:
encToInt()
,
fix_common_encoding_problems()
,
fix_levels_01_spss()
,
has_dont_know()
,
intToEnc()
,
remove_all_dont_know()
,
remove_dont_know()
Data frame with survey data of member satisfaction survey.
membersurvey
membersurvey
data frame
The base R merge will merge data but not all of the attributes. This function also merges the variable.labels attribute.
## S3 method for class 'surveydata' merge(x, y, ...)
## S3 method for class 'surveydata' merge(x, y, ...)
x |
surveydata object |
y |
surveydata object |
... |
Other parameters passed to |
Print open text questions.
print_opentext(data, q, cat = TRUE)
print_opentext(data, q, cat = TRUE)
data |
data |
q |
Question number |
cat |
If TRUE, prints results using |
Other open text functions:
as_opentext_datatable()
print_opentext(membersurvey, "Q33")
print_opentext(membersurvey, "Q33")
Changes vector to ordered factor, adding NA levels if applicable.
question_order(x)
question_order(x)
x |
character vector |
Other Tools:
lapply_names()
Given a question id, e.g. "Q4", returns question text for this question. Note that this returns. The functions question_text_unique()
and question_text_common()
returns the unique and common components of the question text.
question_text(x, Q)
question_text(x, Q)
x |
A surveydata object |
Q |
The question id, e.g. "Q4". If not supplied, returns the text for all questions. |
character vector
Other Question functions:
question_text_common()
,
question_text_unique()
,
questions()
,
split_common_unique()
,
which.q()
# Basic operations on a surveydata object, illustrated with the example dataset membersurvey class(membersurvey) questions(membersurvey) which.q(membersurvey, "Q1") which.q(membersurvey, "Q3") which.q(membersurvey, c("Q1", "Q3")) question_text(membersurvey, "Q3") question_text_unique(membersurvey, "Q3") question_text_common(membersurvey, "Q3") # Extracting columns from a surveydata object head(membersurvey[, "Q1"]) head(membersurvey["Q1"]) head(membersurvey[, "Q3"]) head(membersurvey[, c("Q1", "Q3")]) # Note that the result is always a surveydata object, even if only one column is extracted head(membersurvey[, "id"]) str(membersurvey[, "id"])
# Basic operations on a surveydata object, illustrated with the example dataset membersurvey class(membersurvey) questions(membersurvey) which.q(membersurvey, "Q1") which.q(membersurvey, "Q3") which.q(membersurvey, c("Q1", "Q3")) question_text(membersurvey, "Q3") question_text_unique(membersurvey, "Q3") question_text_common(membersurvey, "Q3") # Extracting columns from a surveydata object head(membersurvey[, "Q1"]) head(membersurvey["Q1"]) head(membersurvey[, "Q3"]) head(membersurvey[, c("Q1", "Q3")]) # Note that the result is always a surveydata object, even if only one column is extracted head(membersurvey[, "id"]) str(membersurvey[, "id"])
Given a question id, e.g. "Q4", finds all sub-questions, e.g. "Q4_1", "Q4_2", etc, and returns the question text that is common to each.
question_text_common(x, Q)
question_text_common(x, Q)
x |
A surveydata object |
Q |
The question id, e.g. "Q4". If not supplied, returns the text for all questions. |
character vector
Other Question functions:
question_text_unique()
,
question_text()
,
questions()
,
split_common_unique()
,
which.q()
# Basic operations on a surveydata object, illustrated with the example dataset membersurvey class(membersurvey) questions(membersurvey) which.q(membersurvey, "Q1") which.q(membersurvey, "Q3") which.q(membersurvey, c("Q1", "Q3")) question_text(membersurvey, "Q3") question_text_unique(membersurvey, "Q3") question_text_common(membersurvey, "Q3") # Extracting columns from a surveydata object head(membersurvey[, "Q1"]) head(membersurvey["Q1"]) head(membersurvey[, "Q3"]) head(membersurvey[, c("Q1", "Q3")]) # Note that the result is always a surveydata object, even if only one column is extracted head(membersurvey[, "id"]) str(membersurvey[, "id"])
# Basic operations on a surveydata object, illustrated with the example dataset membersurvey class(membersurvey) questions(membersurvey) which.q(membersurvey, "Q1") which.q(membersurvey, "Q3") which.q(membersurvey, c("Q1", "Q3")) question_text(membersurvey, "Q3") question_text_unique(membersurvey, "Q3") question_text_common(membersurvey, "Q3") # Extracting columns from a surveydata object head(membersurvey[, "Q1"]) head(membersurvey["Q1"]) head(membersurvey[, "Q3"]) head(membersurvey[, c("Q1", "Q3")]) # Note that the result is always a surveydata object, even if only one column is extracted head(membersurvey[, "id"]) str(membersurvey[, "id"])
Given a question id, e.g. "Q4", finds all sub-questions, e.g. Q4_1, Q4_2, etc, and returns the question text that is unique to each
question_text_unique(x, Q)
question_text_unique(x, Q)
x |
A surveydata object |
Q |
The question id, e.g. "Q4". If not supplied, returns the text for all questions. |
character vector
Other Question functions:
question_text_common()
,
question_text()
,
questions()
,
split_common_unique()
,
which.q()
# Basic operations on a surveydata object, illustrated with the example dataset membersurvey class(membersurvey) questions(membersurvey) which.q(membersurvey, "Q1") which.q(membersurvey, "Q3") which.q(membersurvey, c("Q1", "Q3")) question_text(membersurvey, "Q3") question_text_unique(membersurvey, "Q3") question_text_common(membersurvey, "Q3") # Extracting columns from a surveydata object head(membersurvey[, "Q1"]) head(membersurvey["Q1"]) head(membersurvey[, "Q3"]) head(membersurvey[, c("Q1", "Q3")]) # Note that the result is always a surveydata object, even if only one column is extracted head(membersurvey[, "id"]) str(membersurvey[, "id"])
# Basic operations on a surveydata object, illustrated with the example dataset membersurvey class(membersurvey) questions(membersurvey) which.q(membersurvey, "Q1") which.q(membersurvey, "Q3") which.q(membersurvey, c("Q1", "Q3")) question_text(membersurvey, "Q3") question_text_unique(membersurvey, "Q3") question_text_common(membersurvey, "Q3") # Extracting columns from a surveydata object head(membersurvey[, "Q1"]) head(membersurvey["Q1"]) head(membersurvey[, "Q3"]) head(membersurvey[, c("Q1", "Q3")]) # Note that the result is always a surveydata object, even if only one column is extracted head(membersurvey[, "id"]) str(membersurvey[, "id"])
In many survey systems, sub-questions take the form Q1_a, Q1_b, with the main question and sub-question separated by an underscore. This function conveniently returns all of the main questions in a surveydata()
object. It does this by using the pattern()
attribute of the surveydata object.
questions(x, ptn = pattern(x))
questions(x, ptn = pattern(x))
x |
Object to coerce to surveydata |
ptn |
A list with two elements, |
numeric vector
which.q
Other Question functions:
question_text_common()
,
question_text_unique()
,
question_text()
,
split_common_unique()
,
which.q()
# Basic operations on a surveydata object, illustrated with the example dataset membersurvey class(membersurvey) questions(membersurvey) which.q(membersurvey, "Q1") which.q(membersurvey, "Q3") which.q(membersurvey, c("Q1", "Q3")) question_text(membersurvey, "Q3") question_text_unique(membersurvey, "Q3") question_text_common(membersurvey, "Q3") # Extracting columns from a surveydata object head(membersurvey[, "Q1"]) head(membersurvey["Q1"]) head(membersurvey[, "Q3"]) head(membersurvey[, c("Q1", "Q3")]) # Note that the result is always a surveydata object, even if only one column is extracted head(membersurvey[, "id"]) str(membersurvey[, "id"])
# Basic operations on a surveydata object, illustrated with the example dataset membersurvey class(membersurvey) questions(membersurvey) which.q(membersurvey, "Q1") which.q(membersurvey, "Q3") which.q(membersurvey, c("Q1", "Q3")) question_text(membersurvey, "Q3") question_text_unique(membersurvey, "Q3") question_text_common(membersurvey, "Q3") # Extracting columns from a surveydata object head(membersurvey[, "Q1"]) head(membersurvey["Q1"]) head(membersurvey[, "Q3"]) head(membersurvey[, c("Q1", "Q3")]) # Note that the result is always a surveydata object, even if only one column is extracted head(membersurvey[, "id"]) str(membersurvey[, "id"])
Removes "Do not know" and other similar words from factor levels in data frame
remove_all_dont_know(x, dk = NULL, message = TRUE)
remove_all_dont_know(x, dk = NULL, message = TRUE)
x |
List or data frame |
dk |
Character vector, containing search terms, e.g. |
message |
If TRUE, displays message with the number of instances that were removed. |
A data frame
hasDK()
and removeDK()
Other Functions to clean data:
encToInt()
,
fix_common_encoding_problems()
,
fix_levels_01_spss()
,
has_dont_know()
,
intToEnc()
,
leveltest
,
remove_dont_know()
Tests the levels of x contain any instances of "Don't know". If so, replaces these levels with NA
remove_dont_know(x, dk = "Don't Know")
remove_dont_know(x, dk = "Don't Know")
x |
Character vector or factor |
dk |
Character vector, containing search terms, e.g. |
A factor with "Dont know" removed
Other Functions to clean data:
encToInt()
,
fix_common_encoding_problems()
,
fix_levels_01_spss()
,
has_dont_know()
,
intToEnc()
,
leveltest
,
remove_all_dont_know()
Removes pattern and variable.labels from attributes list.
rm.attrs(x)
rm.attrs(x)
x |
Surveydata object |
Removes pattern from attributes list.
rm.pattern(x)
rm.pattern(x)
x |
Surveydata object |
Get common and unique text in question based on regex pattern identification.
split_common_unique(x, ptn = NULL)
split_common_unique(x, ptn = NULL)
x |
A character vector |
ptn |
A |
Other Question functions:
question_text_common()
,
question_text_unique()
,
question_text()
,
questions()
,
which.q()
Function takes a character string as input and find the common and unique elements. Assumes that the common element is at start of string.
strCommonUnique(string)
strCommonUnique(string)
string |
Character vector |
list of common and unique strings
test <- c("Q_1", "Q_2", "Q_3") strCommonUnique(test)$common strCommonUnique(test)$unique
test <- c("Q_1", "Q_2", "Q_3") strCommonUnique(test)$common strCommonUnique(test)$unique
Plots single and as multi-response questions.
survey_plot_question(data, q)
survey_plot_question(data, q)
data |
surveydata object |
q |
Question |
Other survey plotting functions:
survey_plot_satisfaction()
,
survey_plot_yes_no()
question_text(membersurvey) survey_plot_question(membersurvey, "Q2") survey_plot_yes_no(membersurvey, "Q2") survey_plot_satisfaction(membersurvey, "Q14")
question_text(membersurvey) survey_plot_question(membersurvey, "Q2") survey_plot_yes_no(membersurvey, "Q2") survey_plot_satisfaction(membersurvey, "Q14")
Plot satisfaction questions.
survey_plot_satisfaction(data, q, fun = c("net", "top3", "top2"))
survey_plot_satisfaction(data, q, fun = c("net", "top3", "top2"))
data |
surveydata object |
q |
Question |
fun |
Aggregation function, one of |
Other survey plotting functions:
survey_plot_question()
,
survey_plot_yes_no()
question_text(membersurvey) survey_plot_question(membersurvey, "Q2") survey_plot_yes_no(membersurvey, "Q2") survey_plot_satisfaction(membersurvey, "Q14")
question_text(membersurvey) survey_plot_question(membersurvey, "Q2") survey_plot_yes_no(membersurvey, "Q2") survey_plot_satisfaction(membersurvey, "Q14")
This creates a plot title using [ggplot2::ggtitle()]
. The main title is string wrapped, and the subtitle is the number of observations in the data.
survey_plot_title(data, q, width = 50)
survey_plot_title(data, q, width = 50)
data |
surveydata object |
q |
Question |
width |
Passed to |
Plot data in yes/no format.
survey_plot_yes_no(data, q)
survey_plot_yes_no(data, q)
data |
surveydata object |
q |
Question |
Other survey plotting functions:
survey_plot_question()
,
survey_plot_satisfaction()
question_text(membersurvey) survey_plot_question(membersurvey, "Q2") survey_plot_yes_no(membersurvey, "Q2") survey_plot_satisfaction(membersurvey, "Q14")
question_text(membersurvey) survey_plot_question(membersurvey, "Q2") survey_plot_yes_no(membersurvey, "Q2") survey_plot_satisfaction(membersurvey, "Q14")
In many survey systems, sub-questions take the form "Q1_a", "Q1_b", with the main question and sub-question separated by an underscore. This function conveniently returns column index of matches found for a question id in a surveydata object. It does this by using the pattern attribute of the surveydata
object.
which.q(x, Q, ptn = pattern(x))
which.q(x, Q, ptn = pattern(x))
x |
Object to coerce to surveydata |
Q |
Character string with question number, e.g. "Q2" |
ptn |
A list with two elements, |
questions()
to return all questions matching the pattern()
Other Question functions:
question_text_common()
,
question_text_unique()
,
question_text()
,
questions()
,
split_common_unique()
# Basic operations on a surveydata object, illustrated with the example dataset membersurvey class(membersurvey) questions(membersurvey) which.q(membersurvey, "Q1") which.q(membersurvey, "Q3") which.q(membersurvey, c("Q1", "Q3")) question_text(membersurvey, "Q3") question_text_unique(membersurvey, "Q3") question_text_common(membersurvey, "Q3") # Extracting columns from a surveydata object head(membersurvey[, "Q1"]) head(membersurvey["Q1"]) head(membersurvey[, "Q3"]) head(membersurvey[, c("Q1", "Q3")]) # Note that the result is always a surveydata object, even if only one column is extracted head(membersurvey[, "id"]) str(membersurvey[, "id"])
# Basic operations on a surveydata object, illustrated with the example dataset membersurvey class(membersurvey) questions(membersurvey) which.q(membersurvey, "Q1") which.q(membersurvey, "Q3") which.q(membersurvey, c("Q1", "Q3")) question_text(membersurvey, "Q3") question_text_unique(membersurvey, "Q3") question_text_common(membersurvey, "Q3") # Extracting columns from a surveydata object head(membersurvey[, "Q1"]) head(membersurvey["Q1"]) head(membersurvey[, "Q3"]) head(membersurvey[, c("Q1", "Q3")]) # Note that the result is always a surveydata object, even if only one column is extracted head(membersurvey[, "id"]) str(membersurvey[, "id"])