read_xtabs | R Documentation |
These two functions facilitate reading in Excel spreadsheets of crosstabs generated from SPSS. Note that they're likely only useful for working with the DataHaven Community Wellbeing Survey.
read_xtabs(
path,
name_prefix = "x",
marker = "Nature of the [Ss]ample",
year = NULL,
process = FALSE,
verbose = TRUE,
...
)
read_weights(path, year, marker = "Nature of the [Ss]ample")
path |
Path to an excel file |
name_prefix |
String used to create column names such as x1, x2, x3, ..., Default: 'x' |
marker |
String/regex pattern used to demarcate crosstabs from weight
table. If |
year |
Numeric: year of the survey (or end year, in the case of pooled data).
This tells the functions how to read the files, since formatting has changed
across years of the survey. Because the ability to read a file depends so much
on the year for which it was produced, this argument no longer defaults to a
specific year. Instead, if |
process |
Logical: if |
verbose |
Logical: if |
... |
Additional arguments passed on to |
A data frame. For read_xtabs
, there will be one column per
demographic/geographic group included, plus one for the questions & answers.
For read_weights
, only 2 columns, one for demographic groups and one for
their associated weights.
xtab2df()
if (interactive()) {
xt <- system.file("extdata/test_xtab2018.xlsx", package = "cwi")
read_weights(xt, year = 2018)
# returns a not-very-pretty data frame of the crosstabs to be processed
read_xtabs(xt, year = 2018)
# returns a pretty data frame ready for analysis
read_xtabs(xt, year = 2018, process = TRUE)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.