Re: [R] Getting the index of specific quantiles

2016-11-22 Thread Matteo Richiardi
Thanks Sarah (and all the others who replied) for your precious suggestions! Matteo On 22 November 2016 at 14:18, Sarah Goslee wrote: > Here's how to get one: > > x <- c(9,9,1,3,2,7,6,10,5,6) >> which.min(abs(x - quantile(x, .25))) > [1] 4 > > And here's one of the various ways to get the entire

Re: [R] Getting the index of specific quantiles

2016-11-22 Thread William Dunlap via R-help
You might try something like x <- c(9,9,1,3,2,7,6,10,5,6) p <- (0:4)/4 order(x) [ quantile(seq_along(x),p, type=1) ] # [1] 3 4 7 1 8 Selecting which value of 'type' works makes my head hurt. You could also use 1+(p*(length(x)-1) as the index into order(x). Bill Dunlap TIBCO Software w

Re: [R] Getting the index of specific quantiles

2016-11-22 Thread David Winsemius
> On Nov 22, 2016, at 4:21 AM, Matteo Richiardi > wrote: > > Dear R-users, > a very easy one for you, I guess. I need to extract the indexes of the > elements corresponding to different quantiles of a vector. When a > quantile is an interpolation between two adjacent values, I need the > index

Re: [R] Getting the index of specific quantiles

2016-11-22 Thread Sarah Goslee
Here's how to get one: x <- c(9,9,1,3,2,7,6,10,5,6) > which.min(abs(x - quantile(x, .25))) [1] 4 And here's one of the various ways to get the entire set: > xq <- quantile(x) > sapply(xq, function(y)which.min(abs(x - y))) 0% 25% 50% 75% 100% 34718 Sarah On Tue, Nov 22,

[R] Getting the index of specific quantiles

2016-11-22 Thread Matteo Richiardi
Dear R-users, a very easy one for you, I guess. I need to extract the indexes of the elements corresponding to different quantiles of a vector. When a quantile is an interpolation between two adjacent values, I need the index of the value which is closer (the lower value - or the higher value for w