Learn R Programming

surveydata (version 0.2.7)

questions: Returns a list of all the unique questions in the surveydata object.

Description

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.

Usage

questions(x, ptn = pattern(x))

Value

numeric vector

Arguments

x

Object to coerce to surveydata

ptn

A list with two elements, sep and exclude. See pattern() and which.q() for more detail.

See Also

which.q

Other Question functions: question_text_common(), question_text_unique(), question_text(), split_common_unique(), which.q()

Examples

Run this code
# 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"])

Run the code above in your browser using DataLab