strat_stats: Get summary statistics on a vector of numbers, stratified by...

Description Usage Arguments Details Value Author(s) Examples

View source: R/stats.R

Description

Gives basic statistics for a data item da (ignores NAs), within different levels id.
WARNING - If data is very large, function can encounter serious rounding issues!

Usage

1
strat_stats(id, da, quantiles = NULL)

Arguments

id

vector of any type (except factor) to describe the various levels, with same length as da.

da

numeric vector of data.

quantiles

numeric. Between 0 and 1 to determine 0% - 100% quantile for each id.

Details

Returned data frame contains the following:

id

level identifier.

n

number of items in level.

min

minimum value of da in level.

max

maximum value of da in level.

sum

sum of values of da in level.

mean

mean value of da in level.

median

median value of da in level.

SD

standard deviation value of da in level.

pct_n%

specified quantiles of levels.

Value

A data frame with a row for each level (see Details).

Author(s)

Aaron Hayman

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
 # Want to compare weights of different animals from the following data frame:

 # ANIMAL   WEIGHT
 # Chicken  3.0
 # Cat	    4.2
 # Cat	    3.1
 # Dog	    12.8
 # Cat	    6.1
 # Dog	    20.4
 # Cat	    2.3

 id = c("Chicken", "Cat", "Cat", "Dog", "Cat", "Dog", "Cat")
 da = c(3.0, 4.2, 3.1, 12.8, 6.1, 20.4, 2.3)
 strat_stats(id,da)

 #        id n  min  max  sum   mean median       SD
 # 1     Cat 4  2.3  6.1 15.7  3.925   3.65 1.645955
 # 2 Chicken 1  3.0  3.0  3.0  3.000   3.00      NaN
 # 3     Dog 2 12.8 20.4 33.2 16.600  16.60 5.374012

jgrevel/BAST1-R-Library documentation built on May 21, 2019, 10:11 a.m.