Quantile transformation in R Is there a way to easily create factors based on quantiles of selected variables in a dataframe? Say, in a datatset D, I have variables V1 to V10, which are all numeric. I would like to create dummies for V7 to V10 based on their respective quantiles.
 A: To get the factors, use:
cut(dataset, quantile(dataset))

From the help:
## Default S3 method:
cut(x, breaks)

x          a numeric vector which is to be converted to a factor by cutting.
breaks   either a numeric vector of two or more cut points or a single number (greater than or equal to 2) giving the number of intervals into which x is to be cut.

To use it on multiple columns you could use the data.table package:
df <- data.table(df)
cut_quantile <- function (x) cut(x, quantile(x))
df[, lapply(.SD, cut_quantile), .SDcols = c('V7', 'V8', 'V9', 'V10')]

A: You can use the content method in the bin function in the OneR package for that. It works on vectors and dataframes.
library(OneR)
set.seed(2)
df <- data.frame(a = rnorm(900), b = rnorm(900))
df_bin <- bin(df, nbins = 3, method = "content")
table(df_bin$a)
## 
## (-2.73,-0.385] (-0.385,0.502]   (0.502,2.89] 
##            300            300            300
table(df_bin$b)
## 
## (-4.08,-0.432] (-0.432,0.399]   (0.399,3.17] 
##            300            300            300

(Full disclosure: I am the author of this package)
