Skip to content

Instantly share code, notes, and snippets.

@ltcdnunez
Created February 10, 2013 02:18
Show Gist options
  • Save ltcdnunez/4748030 to your computer and use it in GitHub Desktop.
Save ltcdnunez/4748030 to your computer and use it in GitHub Desktop.
R: Quantile Count
qcount = function(x, g, p, labels) {
d = lapply(split(x, g), function(n) {
q = quantile(unique(n), probs=p, names=F)
as.vector(cut(n, breaks=q, right=T, include.lowest=T, labels=labels), mode="character")
})
d = stack(d)
names(d) = NULL
table(d)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment