This is a fairly basic question, but haven’t seen a good answer on various forums.
Say I’ve a simple vector
x = runif(10,1,4)
> x
[1] 3.292108 1.388526 2.774949 3.005725 3.904919 1.322561 2.660862 1.400743
[9] 2.252095 3.567267
>
Next I compute some quantiles,
> z = quantile(x,c(0.1,0.8))
> z
10% 80%
1.381929 3.347140
>
I need this output as a data frame. So I tried the following
> y = data.frame(id = names(z),values=z)
> y
id values
10% 10% 1.381929
80% 80% 3.347140
I see that the “%” column is repeated. Also when I try
> y$id[1]
[1] 10%
Levels: 10% 80%
whereas I’m expecting it to be either just “10%” or 0.1
Any help appreciated.
The names are just the probabilities so
Would work.
So would wrapping it in a function that returns a
data.frame