groupedstats (version 2.1.0)

grouped_summary: Descriptive statistics for multiple variables for all grouping variable levels

Description

Descriptive statistics for multiple variables for all grouping variable levels

Usage

grouped_summary(
  data,
  grouping.vars,
  measures = NULL,
  measures.type = "numeric",
  topcount.long = FALSE,
  k = 2L,
  ...
)

Arguments

data

Dataframe from which variables need to be taken.

grouping.vars

A list of grouping variables. Please use unquoted arguments (i.e., use x and not "x").

measures

List variables for which summary needs to computed. If not specified, all variables of type specified in the argument measures.type will be used to calculate summaries. Don't explicitly set measures.type = NULL in function call, which will produce an error because the function will try to find a column in a dataframe named "NULL".

measures.type

A character indicating whether summary for numeric ("numeric") or factor/character ("factor") variables is expected (Default: measures.type = "numeric"). This function can't be used for both numeric and variables simultaneously.

topcount.long

If measures.type = factor, you can get the top counts in long format for plotting purposes. (Default: topcount.long = FALSE).

k

Number of digits.

...

Currently ignored.

Value

Dataframe with descriptive statistics for numeric variables (n, mean, sd, median, min, max).

Examples

Run this code
# NOT RUN {
# for reproducibility
set.seed(123)

# another possibility
groupedstats::grouped_summary(
  data = iris,
  grouping.vars = Species,
  measures = Sepal.Length:Petal.Width,
  measures.type = "numeric"
)

# if no measures are chosen, all relevant columns will be summarized
groupedstats::grouped_summary(
  data = ggplot2::msleep,
  grouping.vars = vore,
  measures.type = "factor"
)

# for factors, you can also convert the dataframe to a long format with counts
groupedstats::grouped_summary(
  data = ggplot2::msleep,
  grouping.vars = c(vore),
  measures = c(genus:order),
  measures.type = "factor",
  topcount.long = TRUE
)
# }

Run the code above in your browser using DataLab