Skip to content

Instantly share code, notes, and snippets.

@Keiku
Created January 6, 2017 04:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Keiku/2a117decef4b2000ac1d2dbe2aafd84b to your computer and use it in GitHub Desktop.
Save Keiku/2a117decef4b2000ac1d2dbe2aafd84b to your computer and use it in GitHub Desktop.
Calculate percentiles.
library(dplyr)
library(broom)
mtcars %>%
group_by(cyl) %>%
do(tidy(t(quantile(.$mpg, probs = seq(0, 1, 0.25)))))
# Source: local data frame [3 x 6]
# Groups: cyl [3]
#
# cyl X0. X25. X50. X75. X100.
# <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
# 1 4 21.4 22.80 26.0 30.40 33.9
# 2 6 17.8 18.65 19.7 21.00 21.4
# 3 8 10.4 14.40 15.2 16.25 19.2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment