Skip to contents

Count class observations Creates a new data frame with two columns, listing the classes present in the input data frame, and the number of observations for each class.

Usage

count_classes(data_frame, class_col)

Arguments

data_frame

A data frame or data frame extension (e.g. a tibble).

class_col

Unquoted column name of column containing class labels.

Value

A data frame with two columns. The first column (named class) lists the classes from the input data frame. The second column (named count) lists the number of observations for each class from the input data frame. It will have one row for each class present in input data frame.

Examples

count_classes(mtcars, cyl)
#> # A tibble: 3 × 2
#>   class count
#>   <dbl> <int>
#> 1     4    11
#> 2     6     7
#> 3     8    14