stats0: Descriptive Statistics for a Vector or a Data Frame

View source: R/stats0.R

stats0R Documentation

Descriptive Statistics for a Vector or a Data Frame

Description

Applies descriptive statistics to a vector or a data frame. The function stats0 is a general function. This function is used for extending the basic descriptive statistics functions from the base and stats package. The function prop_miss computes the proportion of missing data for each variable.

Usage

stats0(x, FUN, na.rm=TRUE,...)

max0(x, na.rm=TRUE)
mean0(x, na.rm=TRUE)
min0(x, na.rm=TRUE)
quantile0(x, probs=seq(0, 1, 0.25), na.rm=TRUE)
sd0(x, na.rm=TRUE)
var0(x, na.rm=TRUE)

prop_miss(x)

Arguments

x

Vector or a data frame

FUN

Function which is applied to x

na.rm

Logical indicating whether missing data should be removed

probs

Probabilities

...

Further arguments to be passed

Value

A vector or a matrix

See Also

base::max, base::mean, base::min, stats::quantile, stats::sd, stats::var

Examples

#############################################################################
# EXAMPLE 1: Descriptive statistics toy datasets
#############################################################################

#--- simulate vector y and data frame dat
set.seed(765)
N <- 25    # number of observations
y <- stats::rnorm(N)
V <- 4    # number of variables
dat <- matrix( stats::rnorm( N*V ), ncol=V )
colnames(dat) <- paste0("V",1:V)

#-- standard deviation
apply( dat, 2, stats::sd )
sd0( dat )
#-- mean
apply( dat, 2, base::mean )
mean0( dat )
#-- quantile
apply( dat, 2, stats::quantile )
quantile0( dat )
#-- minimum and maximum
min0(dat)
max0(dat)

#*** apply functions to missing data
dat1 <- dat
dat1[ cbind( c(2,5),2) ] <- NA

#-- proportion of missing data
prop_miss( dat1 )
#-- MAD statistic
stats0( dat, FUN=stats::mad )
#-- SD
sd0(y)

miceadds documentation built on May 29, 2024, 11:05 a.m.