Descriptive Statistics for a Vector or a Data Frame
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.
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)
x |
Vector or a data frame |
FUN |
Function which is applied to |
na.rm |
Logical indicating whether missing data should be removed |
probs |
Probabilities |
... |
Further arguments to be passed |
A vector or a matrix
############################################################################# # 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)
Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.