【问题标题】:r get value only from quantile() functionr 仅从 quantile() 函数中获取值
【发布时间】:2015-04-11 02:34:08
【问题描述】:

对于这个可能是愚蠢的问题,我很抱歉。 当我这样做时:

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

我得到了类似的东西

75% 
1234.5 

有没有办法在没有描述性“75%”字符串的情况下获取值 (1234.5)?非常感谢。

【问题讨论】:

    标签: r quantile


    【解决方案1】:

    你也可以使用unname

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

    您也可以使用[[进行子集化

    > result[[1]]
    [1] 3.25
    

    【讨论】:

    • 甚至names(result) = NULL
    【解决方案2】:

    现在您可以使用names = FALSE 作为参数。

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

    【讨论】:

      【解决方案3】:

      当然,您可以将quantile 的返回值转换为数字。这有效地删除了名称。

      插图:

      > quantile(c(1,2,3,4),0.75)
       75% 
      3.25 
      > as.numeric(quantile(c(1,2,3,4),0.75))
      [1] 3.25
      

      【讨论】:

      • 谢谢杰莉!我刚刚接受了第一个答案,但这也很好用。
      【解决方案4】:

      你可以使用unname()去掉name属性,如:

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

      【讨论】:

      • 感谢 gregor 和 francis!我刚刚接受了第一个答案,但我不知道 unname() 因为我是 R 新手,所以非常感谢 v 提供这些信息。它也可以完美运行
      猜你喜欢
      • 2010-09-10
      • 2015-01-22
      • 2021-04-17
      • 2012-08-23
      • 2012-07-05
      • 2015-12-24
      • 2017-11-05
      • 2023-03-18
      • 2014-09-25
      相关资源
      最近更新 更多