Learn R Programming

tidystats (version 0.5)

count_data: Count the number of observations

Description

count_data returns the number and percentage of observations for categorical variables.

Usage

count_data(data, ..., na.rm = FALSE)

Arguments

data

A data frame.

...

One or more unquoted (categorical) column names from the data frame, separated by commas.

na.rm

Logical. Should missing values (including NaN) be removed?

Details

The data frame can be grouped using dplyr's group_by so that the number of observations will be calculated within each group level.

Examples

Run this code
# NOT RUN {
# Load dplyr for access to the %>% operator and group_by()
library(dplyr)

# 1 variable
count_data(quote_source, source)

# 2 variables
count_data(quote_source, source, sex)

# Ignore missing values
count_data(quote_source, source, sex, na.rm = TRUE)

# Use group_by() to get percentages within each group
quote_source %>%
  group_by(source) %>%
  count_data(sex)

# }

Run the code above in your browser using DataLab