prop_table_by_and_all: Create a standard relative frequency table.

View source: R/tables.R

prop_table_by_and_allR Documentation

Create a standard relative frequency table.

Description

Create a simple relative frequency table with percentages.

Usage

prop_table_by_and_all(
  df,
  dep,
  by_var,
  weights = NULL,
  na.rm = TRUE,
  round_perc = 1
)

Arguments

df

A data.frame.

dep

The name of the dependent variable in the data.frame.

by_var

The name of the group variable in the data.frame.

weights

The name of the weights variable in the data.frame.

na.rm

Set to FALSE to suppress checking for NAs. If TRUE, NAs are removed from x as well as from weights prior to variance estimation.

round_perc

With how many decimals should the percentages be given?

Details

Function is meant to be able to easily rbind various tables.

Value

Returns a data.frame with 1 row.

Examples

# without weights
prop_table_by_and_all(df = mtcars, dep = "cyl", by_var = "gear")

# with weights
mtcars2 <- mtcars
mtcars2[, "weights"] <- rep(c(0.5, 1), 16)
prop_table_by_and_all(df = mtcars2, dep = "cyl", by_var = "gear", weights = "weights")


beckerbenj/eatAnalysis documentation built on July 7, 2023, 5:51 p.m.