Skip to content

replace with quantile value for a large data frame...

2 messages · Ram H. Sharma, Dimitris Rizopoulos

#
one way is the following:

X1 <- c(1:10)
X2 <- c(11:20)
X3 <- c(21:30)
X4 <- c(31:40)
X5 <- c(41:50)
DF <- data.frame(X1, X2, X3, X4, X5)

as.data.frame(sapply(DF, function (x) {
     qx <- quantile(x)
     cut(x, qx, include.lowest = TRUE,
         labels = 1:4)
}))


You may also have a look at function cut2() from package Hmisc.


I hope it helps.

Best,
Dimitris
On 3/13/2011 4:49 PM, Ram H. Sharma wrote: