R/describe.R

Defines functions describe

Documented in describe

#' Generate SPSS-style summary statistics
#'
#' @param x A vector
#' @param table TRUE/FALSE: provide a table of frequencies
#' @param round Number of digits to round
#' @return Returns a list of statistics and values.


describe <- function(x, table=FALSE, round=2){
	stats <- c("N", "Mininum", "Mean", "Maximum", "SD", "Missing")
	values <- round(c(length(x), min(x, na.rm=TRUE), mean(x, na.rm=TRUE), max(x, na.rm=TRUE), sd(x, na.rm=TRUE), sum(is.na(x))), round)
	ifelse(table, return(list("Summary Statistics" = rbind(stats, values),
				  "Frequencies" = table(round(x, 2)))),
				  return(rbind(stats, values)))
}
michaelpmcdonald/rgo documentation built on May 22, 2019, 9:52 p.m.