r get value only from quantile() function
Asked Answered
T

4

41

I'm sorry for what may be a silly question. When I do:

> quantile(df$column, .75) #get 3rd quartile

I get something like

75% 
1234.5 

Is there a way to just get the value (1234.5) without the descriptive "75%" string? Thank you very much.

Teetotaler answered 10/2, 2015 at 21:31 Comment(0)
H
45

You can also use unname

> result <- quantile(c(1,2,3,4),0.75)
> unname(result)
[1] 3.25

Also you can subset by using [[

> result[[1]]
[1] 3.25
Hydrophilous answered 10/2, 2015 at 21:38 Comment(1)
Or even names(result) = NULLFractionate
J
16

Now you can use names = FALSE as argument.

> quantile(c(1,2,3,4),0.75, names = FALSE)
[1] 3.25
Jewelfish answered 8/5, 2018 at 15:6 Comment(0)
F
8

Sure, you can just convert the returned value of quantile to a numeric. This effectively removes the names.

Illustration:

> quantile(c(1,2,3,4),0.75)
 75% 
3.25 
> as.numeric(quantile(c(1,2,3,4),0.75))
[1] 3.25
Fractionate answered 10/2, 2015 at 21:35 Comment(1)
Thanks jealie! I just accepted the first answer but this works great too.Teetotaler
C
4

You can use unname() to remove the name attribute, as in:

> unname(quantile(df$column, .75))
[1] 75
Colophon answered 10/2, 2015 at 21:39 Comment(1)
Thanks gregor and francis! I just accepted the first answer, but I did not know about unname() as I am new to R, so thanks v much for this info. It also works perfectlyTeetotaler

© 2022 - 2024 — McMap. All rights reserved.