在任何列中找到具有异常值的行

问题描述 投票:0回答:1

在数据框df中提供如下所示的数据,需要提取任何列具有离群值的行。

text = "
A,B,C,D,E,F,G
93,53,221,314,104,721,179
100,58,218,318,93,718,181
601,61,228,829,106,739,190
510,60,229,739,95,707,181
779,51,242,1021,105,756,180
848,57,228,1076,93,710,191
94,52,227,321,95,723,179
712,58,242,954,486,750,180
,53,,10289,298,841,210
696,53,233,929,95,751,180
101,57,220,321,415,796,179
100,60,226,326,104,744,180
181,58,234,415,105,2870,468
,57,,10277,,,918
"
df = read.table(textConnection(text), sep=",", header = T)

异常值在箱图中定义-Q1-1.5IQR / Q3 + 1.5IQR。因此,具有任意列(一个或多个)的列具有离群值的行将出现在我们的输出集中。

还希望获得第二组行,其中任何列值仅在Q3 + 1.5IQR值之上的行将代替上面的经典定义,而是我们的输出集中的行。

我面临一些挑战,请完成此任务。我在想的伪代码如下

  1. 计算每列的箱线图统计信息
  2. 使用Q1和Q3值获取列值> Q3和
  3. 关于#1,我已经尝试了以下方法

> sapply(df, boxplot.stats)
      A         B         C         D         E         F         G        
stats Numeric,5 Numeric,5 Numeric,5 Numeric,5 Numeric,5 Numeric,5 Numeric,5
n     12        14        12        14        13        13        14       
conf  Numeric,2 Numeric,2 Numeric,2 Numeric,2 Numeric,2 Numeric,2 Numeric,2
out   Integer,0 Integer,0 Integer,0 Integer,2 Integer,3 Integer,2 Integer,3

但是这似乎无法提供可能在#2中使用的类似stats a vector of length 5, containing the extreme of the lower whisker, the lower ‘hinge’, the median, the upper ‘hinge’ and the extreme of the upper whisker.的输出。

在数据框df中提供如下所示的数据,需要提取对任何列均具有离群值的行。 text =“ A,B,C,D,E,F,G,93,53,221,314,104,721,179 100,58,218,318,93,718,181 601,61,228,829,106,...

r dataframe outliers
1个回答
0
投票

我们可以编写一个函数来确定该值是否是异常值

© www.soinside.com 2019 - 2024. All rights reserved.