vgrabovets
10/5/2016 - 7:20 PM

statSummary

statSummary

statSummary = function(df, val) {
  dots = list(
    n_ = lazyeval::interp(~ n()),
    min_ = lazyeval::interp(~ min(x, na.rm = TRUE), x = as.name(val)),
    q1_ = lazyeval::interp(~ quantile(x,.25, na.rm=TRUE), x = as.name(val)),
    median_ = lazyeval::interp(~ median(x, na.rm=TRUE), x = as.name(val)),
    mean_ = lazyeval::interp(~ mean(x, na.rm=TRUE), x = as.name(val)),
    q3_ = lazyeval::interp(~ quantile(x,.75, na.rm=TRUE), x = as.name(val)),
    max_ = lazyeval::interp(~ max(x, na.rm = TRUE), x = as.name(val)),
    sd_ = lazyeval::interp(~ sd(x, na.rm = TRUE), x = as.name(val))
  )
  df %>% summarise_(.dots = setNames(dots, c('n', 'min', 'Q1', 'median', 'mean',
                                             'Q3', 'max', 'sd')))
}