Skip to content
Prev 312507 / 398506 Next

subgroup-based quantiles

Hello,

If you want Age quantiles by gender, you have to split the data by 
gender, apply the same code then recombine the result.


fun <- function(x){
     Age_group <- cut(x[, "Age"], labels=c(1:10),
         breaks=quantile(x[, "Age"], seq(0,1,.1)),
         include.lowest = TRUE)
     cbind(x, Age_group)
}

result <- do.call(rbind, lapply(split(dat, dat[, "GENDER"]), fun))
rownames(result) <- seq_len(nrow(result))
result


Hope this helps,

Rui Barradas
Em 30-11-2012 12:18, R Kozarski escreveu: