How to get a simple numeric value from a named numeric vector in R?

I use R to calculate some basic statistical results. I use the quantile () function to calibrate the quantiles in a data frame column as follows.

> quantile(foobars[,1])
     0%     25%     50%     75%    100% 
 189000  194975  219500  239950 1000000 

I want to be able to individually access the calculated quantiles. However, I cannot figure out how to do this. When I check the return class, this is a one-dimensional number.

I tried this:

> q <- quantile(foobars[,1])
> q[3]
   50% 
219500

The tuple seems to return (quantile level + number). I am only interested in the number (219500 in this case.

How can I access only the number in a simple (numeric) variable?

+5
source share
1 answer

. R, q :

> dat <- rnorm(100)
> q <- quantile(dat)
> q
        0%        25%        50%        75%       100% 
-2.2853903 -0.5327520 -0.1177865  0.5182007  2.4825565 
> str(q)
 Named num [1:5] -2.285 -0.533 -0.118 0.518 2.483
 - attr(*, "names")= chr [1:5] "0%" "25%" "50%" "75%" ...

"named" , "names", ( ) . R , , . , . , "names":

> q[3] + 10
     50% 
9.882214

, unname(), :

> q2 <- unname(q)
> q2
[1] -2.2853903 -0.5327520 -0.1177865  0.5182007  2.4825565

, "names" names(), ('names<-'()). , - NULL :

> q3 <- q
> names(q3)
[1] "0%"   "25%"  "50%"  "75%"  "100%"
> names(q3) <- NULL
> names(q3)
NULL
+16

All Articles