calculate_proportions: Calculate the proportion of each category from one variable.

View source: R/wrangle.R

calculate_proportionsR Documentation

Calculate the proportion of each category from one variable.

Description

This function creates a data.frame which includes 3 columns.

  1. a column containing the variable's categories;

  2. a column containing each category's frequency;

  3. a column containing each category's proportion.

Usage

calculate_proportions(data, variable)

Arguments

data

An object of type data.frame.

variable

The name of the variable from which to calculate the proportions.

Value

A data.frame which includes 3 columns.

  1. variable: a column containing the variable's categories;

  2. n: a column containing each category's frequency;

  3. prop: a column containing each category's proportion.

Author(s)

CLESSN

Examples


## Not run: 

# Calculate the proportions of each cylinder configuration
# from mtcars.

calculate_proportions(mtcars,cyl)

## End(Not run)

clessn/clessn-verse documentation built on Feb. 18, 2024, 12:42 p.m.