describe <- function(df,...)
    stop("First argument must be a data frame")
  df <- df[!sapply(df, is.character)]
  if(length(names(df)) == 0)
    stop("No numeric variables found.")
  if (nargs() > 1)
      df <- df %>% select(...)
  # Create a string var with factor levels
  factorLevels <- sapply(df, function(x)ifelse(is.factor(x),
    ifelse(str_length(fd <- str_c(levels(x), collapse = '/')) < 10, fd, str_c(length(levels(x)), " levels") ),
  hasFactors <- any(sapply(df, is.factor))
  df <- df %>% mutate_each(funs(as.numeric))
  dfout <- sapply(c(mean=mean, min=min, max=max, n=function(x,...)sum(,
    function(x){sapply(df, x, na.rm=TRUE)})
  # Handle strange behavior of sapply when there is only one variable
  if(length(df) == 1) {
    dfout <- t(as.matrix(dfout))
    rownames(dfout) <- names(df)
    colnames(dfout) <- c("mean","min","max","n")
  dfout <-
    dfout$factor <- factorLevels

R Markdown

This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see

When you click the Knit button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:

describe(iris, matches("Sep"))

Including Plots

You can also embed plots, for example:


Note that the echo = FALSE parameter was added to the code chunk to prevent printing of the R code that generated the plot.

bjornerstedt/assist documentation built on Sept. 8, 2017, 2:02 p.m.