Skip to content
Prev 308196 / 398503 Next

loop of quartile groups

Hello,

There's no function cut2() but it's not very difficult to write one. 
I've named your data example 'dat', it saves keystrokes.
Try the following.

dat <- structure(...etc...)

cut2 <- function(x, g = 0){
     cut(x, breaks = c(-Inf, seq(min(x), max(x), length.out = g)))
}

fun <- function(x) {
     ct <- cut2(x, g = 4)
     factor(ct, levels = levels(ct), labels=1:4)
}

tmp <- sapply(dat[-1], fun)
colnames(tmp) <- paste("quartile", colnames(tmp), sep="_")
dat2 <- cbind(dat, tmp)
str(dat2)


Hope this helps,

Rui Barradas
Em 17-10-2012 15:23, Charles Determan Jr escreveu: