sumstats: Simple summary statistics

Description Usage Arguments Value Examples

View source: R/sumstats.R

Description

Generate a simple set of summary statistics for a numeric vector or the numeric columns of a data.frame over various subsets. There are MANY other ways to do this but this function is suitable to my needs.

Usage

1
2
3
4
5
6
7
8
sumstats(data, ...)

## S3 method for class 'numeric'
sumstats(data, digits = 2, ...)

## S3 method for class 'data.frame'
sumstats(data, f = NULL, digits = 2, order = TRUE,
  ...)

Arguments

data

a data.frame or numeric vector.

...

additional arguments passed onto various methods.

digits

an integer to specify the number of decimal places desired for the resulting summary statistics. Passed directly to round().

f

a formula. See the examples and aggregate for details.

order

a logical value. If TRUE (default), the rows of the resulting data.frame will be first sorted alphabetically by the variables specified in the left-hand side of f then according to the permutations of the grouping factors specified in the right-hand side of f. If FALSE, the rows will be sorted only by permutations of the grouping factors.

Value

a data.frame in which each row represents a variable-grouping permutation.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
# Numeric vector
sumstats(mtcars$disp)
# All variables summarized and no grouping
sumstats(mtcars)
sumstats(iris)
# Only 'Petal.Width' and 'Sepal.Width' summarize and no grouping
sumstats(iris, cbind(Petal.Width, Sepal.Width) ~ NULL)
# All variables summarized and grouped by 'Species'
sumstats(iris, . ~ Species)
# 'mpg' and 'wt' summarized by 'cyl' and 'vs'
sumstats(mtcars, cbind(mpg, wt) ~ cyl + vs)
sumstats(mtcars, cbind(mpg, wt) ~ cyl + vs, order = FALSE)

sboysel/boysel documentation built on May 29, 2019, 3:24 p.m.