Skip to contents

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.

Usage

dta_freq_mrq(
  dat,
  .columns,
  value,
  name = "Options",
  add_percent_symbol = TRUE,
  digits = 2
)

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)
Programming proficiency Frequency Responses Cases
R 1245 16.79% 49.80%
Python 1267 17.09% 50.68%
SAS 1266 17.08% 50.64%
Stata 1225 16.53% 49.00%
SPSS 1222 16.48% 48.88%
Microsoft Excel 1188 16.03% 47.52%
Total 7413 100.00% 296.52%
# 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)
Programming proficiency Frequency Responses Cases
R 1245 16.79 49.80
Python 1267 17.09 50.68
SAS 1266 17.08 50.64
Stata 1225 16.53 49.00
SPSS 1222 16.48 48.88
Microsoft Excel 1188 16.03 47.52
Total 7413 100.00 296.52
# 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)])
Smart TV Tablet Desktop Computer Digital Camera Smartphone Smartwatch Laptop
TRUE TRUE TRUE TRUE TRUE FALSE FALSE
TRUE FALSE FALSE FALSE TRUE FALSE FALSE
TRUE TRUE TRUE FALSE FALSE TRUE TRUE
TRUE TRUE TRUE TRUE TRUE FALSE FALSE
FALSE FALSE TRUE FALSE FALSE TRUE FALSE
FALSE TRUE TRUE FALSE FALSE TRUE FALSE
FALSE FALSE FALSE TRUE FALSE TRUE FALSE
FALSE FALSE FALSE TRUE FALSE TRUE FALSE
FALSE TRUE FALSE TRUE FALSE TRUE FALSE
FALSE FALSE TRUE FALSE TRUE FALSE FALSE
result3 <- dta_freq_mrq( dat = dat, .columns = starts_with("gad_"), value = TRUE, name = "Programming proficiency" ) dta_gtable(result3)
Programming proficiency Frequency Responses Cases
Smart TV 1087 14.46% 43.48%
Tablet 1099 14.62% 43.96%
Desktop Computer 1061 14.11% 42.44%
Digital Camera 1034 13.75% 41.36%
Smartphone 1029 13.69% 41.16%
Smartwatch 1091 14.51% 43.64%
Laptop 1117 14.86% 44.68%
Total 7518 100.00% 300.72%
# 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)])
Smart TV Tablet Desktop Computer Digital Camera Smartphone Smartwatch Laptop
1 1 1 1 1 0 0
1 0 0 0 1 0 0
1 1 1 0 0 1 1
1 1 1 1 1 0 0
0 0 1 0 0 1 0
0 1 1 0 0 1 0
0 0 0 1 0 1 0
0 0 0 1 0 1 0
0 1 0 1 0 1 0
0 0 1 0 1 0 0
result4 <- dta_freq_mrq( dat = dat2, .columns = starts_with("gad_"), value = 1, name = "Programming proficiency" ) dta_gtable(result4)
Programming proficiency Frequency Responses Cases
Smart TV 1087 14.46% 43.48%
Tablet 1099 14.62% 43.96%
Desktop Computer 1061 14.11% 42.44%
Digital Camera 1034 13.75% 41.36%
Smartphone 1029 13.69% 41.16%
Smartwatch 1091 14.51% 43.64%
Laptop 1117 14.86% 44.68%
Total 7518 100.00% 300.72%