Learn R Programming

descriptr (version 0.6.1)

ds_group_summary: Groupwise descriptive statistics

Description

Descriptive statistics of a continuous variable for the different levels of a categorical variable. plot.ds_group_summary() creates boxplots of the continuous variable for the different levels of the categorical variable.

Usage

ds_group_summary(data, group_by, cols)

# S3 method for ds_group_summary plot(x, print_plot = TRUE, ...)

Value

ds_group_summary() returns an object of class "ds_group_summary". An object of class "ds_group_summary" is a list containing the following components:

stats

A data frame containing descriptive statistics for the different levels of the factor variable.

tidy_stats

A tibble containing descriptive statistics for the different levels of the factor variable.

plotdata

Data for boxplot method.

Arguments

data

A data.frame or a tibble.

group_by

Column in data.

cols

Column in data.

x

An object of the class ds_group_summary.

print_plot

logical; if TRUE, prints the plot else returns a plot object.

...

Further arguments to be passed to or from methods.

Details

Groups with missing values in the continuous variable are summarised using the non-missing observations (na.rm = TRUE), and the number of missing observations is reported in the Missing row of stats. Observations with a missing grouping label are excluded from the summary and from the boxplot. Unused levels of the grouping factor are dropped.

The grouping key in tidy_stats keeps the class of the grouping variable (including ordered factors) and the order of the observed levels. If the grouping column is named like one of the statistic columns, such as length, its column in tidy_stats is suffixed with _group so that every column name is unique.

See Also

ds_summary_stats

Examples

Run this code
# ds_group summary
ds_group_summary(mtcarz, cyl, mpg)

# boxplot
k <- ds_group_summary(mtcarz, cyl, mpg)
plot(k)

# tibble
k$tidy_stats

Run the code above in your browser using DataLab