【问题标题】:How can I get a percentile value for each dataframe row considering a subset of the data?考虑到数据的子集,如何获得每个数据框行的百分位值?
【发布时间】:2015-07-16 15:24:04
【问题描述】:

我有一个 145 行和 1000 多列的数据框 obs。

对于每一行,我想提取第 95 个百分位数的值,但仅根据大于或等于 1 的数据进行计算。

考虑到所有数据,我设法为每一行计算一个值,如下所示:

p95.obs <- apply(obs,1,quantile,probs=c(.95))

要包含我尝试过的大于选项

p95.obs <- apply(obs>=1,1,quantile,probs=c(.95))

但是这样我每行只得到1个。

【问题讨论】:

    标签: r dataframe quantile


    【解决方案1】:

    你可以试试

     apply(obs, 1, function(x) quantile(x[x>=1], probs=.95))
    

    【讨论】:

      猜你喜欢
      • 2023-02-04
      • 2018-11-21
      • 1970-01-01
      • 2019-08-03
      • 2018-01-01
      • 1970-01-01
      • 2011-09-09
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多