简体   繁体   English

r仅从quantile()函数获取值

[英]r get value only from quantile() function

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? 有没有办法获得没有描述性“75%”字符串的值(1234.5)? Thank you very much. 非常感谢你。

You can also use unname 您也可以使用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

Now you can use names = FALSE as argument. 现在您可以使用names = FALSE作为参数。

> quantile(c(1,2,3,4),0.75, names = FALSE)
[1] 3.25

Sure, you can just convert the returned value of quantile to a numeric. 当然,您可以将quantile的返回值转换为数字。 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

You can use unname() to remove the name attribute, as in: 您可以使用unname()删除name属性,如下所示:

> unname(quantile(df$column, .75))
[1] 75

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM