dstats {prettyR} | R Documentation |
calculates mean, variance or standard deviation and n for numeric variables
dstats(x,indices=NA,do.sd=FALSE)
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 |
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.
A matrix of three rows with the number of columns equal to the number of variables used.
Mean |
the results of applying the mean function |
Variance or SD |
the results of applying the var function
or the square root of that if do.sd is TRUE |
n |
the number of observations that are NOT NA |
Jim Lemon
test.df<-data.frame(A=sample(1:100,20),B=rnorm(20),C=sample(LETTERS,20)) dstats(test.df)