Make a table showing the number (n) and percent of the population (e.g. % of nrow()) for each value in a variable(s).

make_n_and_percent_table(data, columns)

Arguments

data

A data.frame with the data you want to make the table from.

columns

A string or vector of strings with the column names to make the N and % from.

Value

A data.frame with one row for each value in the inputted variable(s) and columns showing the N and % for that value.

Examples

make_n_and_percent_table(mtcars, c("cyl", "gear"))
#>   Variable Description  N Percent
#> 1      Cyl           8 14   43.75
#> 2                    4 11   34.38
#> 3                    6  7   21.88
#> 4     Gear           3 15   46.88
#> 5                    4 12   37.50
#> 6                    5  5   15.62