Another way would be ntile()
in dplyr
.
library(tidyverse)
foo <- data.frame(a = 1:100,
b = runif(100, 50, 200),
stringsAsFactors = FALSE)
foo %>%
mutate(quantile = ntile(b, 10))
# a b quantile
#1 1 93.94754 2
#2 2 172.51323 8
#3 3 99.79261 3
#4 4 81.55288 2
#5 5 116.59942 5
#6 6 128.75947 6