Learn R Programming

prettyR (version 1.0-4)

dstats: Simple descriptive statistics for numeric variables

Description

calculates mean, variance or standard deviation and n for numeric variables

Usage

dstats(x,indices=NA,do.sd=FALSE)

Arguments

x
data frame, matrix or vector containing numeric variables
indices
which columns of the data frame or matrix to use
do.sd
logical - return standard deviation rather than variance

Value

  • A matrix of three rows with the number of columns equal to the number of variables used.
  • Meanthe results of applying the mean function
  • Variance or SDthe results of applying the var function or the square root of that if do.sd is TRUE
  • nthe number of observations that are NOT NA

Details

dstats will accept a vector, matrix or data frame. It calculates the mean, variance and valid n for the columns specified by indices. If indices is not specified, it will be calculated for the columns that return TRUE from as.numeric. If do.sd is TRUE, it returns standard deviations rather than variances. Valid ns are calculated as the number of observations that are NOT NA.

See Also

mean,var

Examples

Run this code
test.df<-data.frame(A=sample(1:100,20),B=rnorm(20),C=sample(LETTERS,20))
 dstats(test.df)

Run the code above in your browser using DataLab