QuestionMap | R Documentation |
An R6 QuestionMap
object holds the mapping for
one question or demographic between the sample data and population data.
new()
Create a new QuestionMap
QuestionMap$new(name, col_names, values_map)
name
The name of the underlying construct. For example if the
sample data uses the name "age_bracket"
and the population data uses
the name "age_group"
then name
could be "age"
. This name will be
used later in the workflow when creating a data set with unified names.
col_names
A character vector of length two giving the column names of the question in the sample data (first element) and the population data (second element).
values_map
A named list where the names correspond to the responses to the question in the sample data and the values correspond to the responses in the population data. In some cases multiple values in the sample may correspond to a single value in the population, or vice versa (e.g., the sample survey has age groups 18-25 and 26-35 but the population data only uses 18-35, see Examples).
If there is a meaningful ordering over the values, they should be listed in that order, either descending or ascending. Note that if responses were given with both the values in the data and the actual responses given (useful as these will be used for plotting), the mapping should use the values in the data (generally shorter). See Examples.
A QuestionMap
object that can be added to a SurveyMap
object.
q_age <- QuestionMap$new( name = "age", col_names = c("age","age_group"), values_map = list( "18-25" = "18-35", "26-35" = "18-35", "36-45" = "36-55", "46-55" = "36-55", "56-65" = "56-65", "66-75" = "66+", "76-90" = "66+" ) ) print(q_age) q_gender <- QuestionMap$new( name = "gender", col_names = c("gender", "gender"), values_map = list("male" = "m","female" = "f", "nonbinary" = "nb") ) print(q_gender) q_party_pref <- QuestionMap$new( name = "party_pref", col_names = c("vote_for", "vote_pref"), values_map = list( "Box Party" = "The BP", "The BP" = "The BP", "The Circle Party" = "The Circles", "The Circles" = "The Circles" ) ) print(q_party_pref)
print()
Print a QuestionMap
.
QuestionMap$print(...)
...
Currently ignored.
The QuestionMap
object, invisibly.
name()
Access name
QuestionMap$name()
A string.
col_names()
Access col_names
QuestionMap$col_names()
A character vector of length 2.
values()
Access values
QuestionMap$values()
A data frame.
clone()
The objects of this class are cloneable with this method.
QuestionMap$clone(deep = FALSE)
deep
Whether to make a deep clone.
## ------------------------------------------------
## Method `QuestionMap$new`
## ------------------------------------------------
q_age <- QuestionMap$new(
name = "age",
col_names = c("age","age_group"),
values_map = list(
"18-25" = "18-35",
"26-35" = "18-35",
"36-45" = "36-55",
"46-55" = "36-55",
"56-65" = "56-65",
"66-75" = "66+",
"76-90" = "66+"
)
)
print(q_age)
q_gender <- QuestionMap$new(
name = "gender",
col_names = c("gender", "gender"),
values_map = list("male" = "m","female" = "f", "nonbinary" = "nb")
)
print(q_gender)
q_party_pref <- QuestionMap$new(
name = "party_pref",
col_names = c("vote_for", "vote_pref"),
values_map = list(
"Box Party" = "The BP",
"The BP" = "The BP",
"The Circle Party" = "The Circles",
"The Circles" = "The Circles"
)
)
print(q_party_pref)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.