I’m trying to create a table of quantiles in R for multiple subsets of data.
Right now, I have a vector of ids (p_ids) in table DATA, which are not consecutive. For each value in p_ids, I am looking to list the quantiles.
So far, I’ve tried variations of:
i <- 1
n <- 1
for (i in p_ids) {
while(n <= nrow(data)) {
quantiles[n] <- quantile(subset(alldata$variableA, alldata$variableB == i),
probs = c(0,1,2,3)/3)
n <- n + 1
}
}
I know my issue lies somewhere in the index, but I can’t seem to get where the index should go. Suggestions?
You should look into using aggregate to do your quantiles for you
http://stat.ethz.ch/R-manual/R-devel/library/stats/html/aggregate.html
setting FUN=quantiles and by=p_ids should do what you want.
That is unless I’ve misunderstood your question.