删除数据框中大于95百分位数的数据

use*_*980 15 r

我有这样的数据:

DF:

Group   Point
A       6000
B       5000
C       1000
D        100
F        70
Run Code Online (Sandbox Code Playgroud)

在我绘制这个df之前,我只想删除数据框中超过95百分位数的值.有谁告诉我该怎么做?

GSe*_*See 38

使用该quantile功能

> quantile(d$Point, 0.95)
 95% 
5800 

> d[d$Point < quantile(d$Point, 0.95), ]
  Group Point
2     B  5000
3     C  1000
4     D   100
5     F    70
Run Code Online (Sandbox Code Playgroud)


swo*_*iak 5

或使用'dplyr'库:

> quantile(d$Point, 0.95)
 95% 
5800

> df %>% filter(Point < quantile(df$Point, 0.95))
  Group Point
1     B  5000
2     C  1000
3     D   100
4     F    70
Run Code Online (Sandbox Code Playgroud)

  • 您甚至可以不指定df而缩短:df%&gt;%filter(Point &lt;分位数(Point,0.95))。 (4认同)