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
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
> 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
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,
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
5 matches
Mail list logo