Skip to content

Instantly share code, notes, and snippets.

@nstrayer
Created October 6, 2017 17:34
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 nstrayer/bdf0f895593ffcf9742f9155012701c4 to your computer and use it in GitHub Desktop.
Save nstrayer/bdf0f895593ffcf9742f9155012701c4 to your computer and use it in GitHub Desktop.
library(tidyverse)
data_frame(
x = 1:100,
y = rnorm(100)
) %>%
mutate( y_quartile = ntile(y, 4) ) %>%
head(5)
# # A tibble: 5 x 3
# x y y_quartile
# <int> <dbl> <int>
# 1 1 -0.8521091 1
# 2 2 -2.2174697 1
# 3 3 1.1815976 4
# 4 4 0.9591009 4
# 5 5 -0.4436867 2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment