xtab2df | R Documentation |
Like read_xtab
& read_weights
, this is a bespoke function
to make it easier to extract data from the DataHaven Community Wellbeing
Survey. Applications to other crosstabs are probably limited unless their
formatting is largely the same. After reading a crosstab excel file, xtab2df
extracts the question codes (e.g. Q4A), question text, categories, and
demographic groups, and joins those descriptions with survey responses and
values, making it ready for analysis.
xtab2df(.data, col = x1, code_pattern = "^[A-Z\\d_]{2,20}$")
.data |
A data frame as returned from |
col |
The bare column name of where to find question codes and text.
Default: x1, based on names assigned by |
code_pattern |
String: regex pattern denoting how to find cells that
contain only a question code, such as "Q10", "Q4B", or "ASTHMA". This is
pretty finicky, so you probably don't want to change it.
Default: |
A data frame with the following columns:
code (if questions have codes in crosstabs)
q_number (if questions don't have codes in crosstabs, assigned in order they occur)
question
category (e.g. age, gender)
group (e.g. 18–34, male)
response
value
read_xtabs()
if(interactive()){
xtab <- read_xtabs(system.file("extdata/test_xtab2018.xlsx", package = "cwi"))
xtab2df(xtab)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.