get_n_percent: Get count and percentage. By group.

View source: R/funcs.R

get_n_percentR Documentation

Get count and percentage. By group.

Description

Gets count and percentage for factor variables by group. NAs and empty strings are converted to a separate level "Missing" Does a chisquare test if the 'output' argument has a p value column in it. Unless ID variable is specified, the denominator is the number of rows in the dataset.

Usage

get_n_percent(
  data,
  strata,
  variable,
  name,
  output,
  id = "",
  round = 2,
  sort_by_freq = FALSE
)

Arguments

data

tibble containing data. Can't be a grouped tibble

strata

variable to stratify output by. Needs to be a factor to force to ordering to work.

variable

Ideally a factor variable. If not, gets converted to factor anyway.

name

string name to put into the row

output

The dataframe to append the requested summary to

id

Optional. Character vector containing name of variable to use when counting the denominator. Allows the sum of the numerators to be greater than 100 if there is more than one row per denominator variable.

round

The number of decimal places to round results to

sort_by_freq

TRUE/FALSE for whether to overwrite factor ordering and sort in descending order of total frequency.


aasiyahrashan/TableOneDataframe documentation built on Dec. 9, 2024, 4:33 p.m.