prop_multi: Compute the proportion of items for multiple non exclusive...

Description Usage Arguments Details Value See Also Examples

View source: R/prop_multi.R

Description

Uses an id variable and groupings to calculate proportions in a multiple-choice (checkbox) scenario. I.e., answer proportions sum to more than 100

Usage

1
prop_multi(x, ..., idvar)

Arguments

x

a tbl() to compute proportions, this can be a grouped tbl()

...

Variables to group by.

idvar

the response id variable name as *string* (from which distinct respondents are to be computed)

Details

The function uses the variables names specificed in ..., to conduct a grouping

With a variable name in ..., calculates proportions cases of variable out of the total n unique idvar grouped by the variable. with a variable name in ... and pre grouped data, calc proportions cases of variable out of the total n unique idvar in the pregrouped cathegories grouped by the variable.

Value

A tbl, grouped the same way as x, with the proportions computed out of the distinct respondents. If x is grouped before the ..., the total of the distinct respondents will be calculated out of level of the previous groupings and not from the whole x data.

See Also

prop, add_prop

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
multi_choice <- tribble(~id, ~choice, ~yr,
                        1, "A", 2017,
                        1, "B", 2017,
                        1, "A", 2018,
                        2, "A", 2019,
                        2, "C", 2019,
                        2, "A", 2017,
                        3, "A", 2017,
                        3, "A", 2018)

# disregard the yr variable
multi_choice %>%
   prop_multi(choice, idvar = id)

# add the yr variable as a pre-grouping variable and use it as well
multi_choice %>%
   group_by(yr) %>%
   prop_multi(choice, idvar = "id")

sarid-ins/saridr documentation built on Nov. 10, 2020, 9:07 p.m.