dta_freq_mrq()
generates a frequency table for multiple response
questions, calculating the counts and percentages for the specified values
(e.g., "Yes"
) across multiple columns. It also adds a total row with
the summed counts and percentage responses.
Arguments
- dat
A data frame containing the data to be analyzed.
- .columns
A list of columns (or unquoted column names) to analyze. Multiple columns can be passed.
- value
The value to count in the responses (default is
"Yes"
).- name
The name to be used for the first column in the result Default is
"Options"
.- add_percent_symbol
Logical indicating whether or not to add a % sign to percentages. Default is
TRUE
.- digits
The number of digits to round the percentage responses to (default is 2).
Value
A data frame containing the frequency counts, percentage responses, and total values. The columns will be:
- Options
The different response options for the multiple response question
- Frequency
The count of each response option
- Responses
The percentage of each response option relative to the total count
- Cases
The percentage of the category specified by
value
Examples
data("data_sample")
# An example with multiple response variables labelled
# as Yes / No
result <- dta_freq_mrq(
dat = data_sample,
.columns = r:excel,
value = "Yes",
name = "Programming proficiency"
)
dta_gtable(result)
# Remove the percentage symbol
result2 <- dta_freq_mrq(
dat = data_sample,
.columns = r:excel,
value = "Yes",
name = "Programming proficiency",
add_percent_symbol = FALSE
)
dta_gtable(result2)
# An example with TRUE / FALSE. First generate multiple
# response variables with TRUE / FALSE values
dat <- dta_mrq(
dat = data_sample,
.column = gadgets_owned,
delimeter = ", ",
prefix = "gad_"
)
dta_gtable(dat[1:10, (ncol(dat) - 6):ncol(dat)])
result3 <- dta_freq_mrq(
dat = dat,
.columns = starts_with("gad_"),
value = TRUE,
name = "Programming proficiency"
)
dta_gtable(result3)
# An example with numeric codes 0 / 1
dat2 <- dta_mrq(
dat = data_sample,
.column = gadgets_owned,
delimeter = ", ",
prefix = "gad_",
as_numeric = TRUE
)
dta_gtable(dat2[1:10, (ncol(dat2) - 6):ncol(dat2)])
result4 <- dta_freq_mrq(
dat = dat2,
.columns = starts_with("gad_"),
value = 1,
name = "Programming proficiency"
)
dta_gtable(result4)