remove outliers in r very easy?

主宰稳场 提交于 2019-12-01 23:29:24

boxplot$out is returning the values for the outliers and not the positions of the outliers. So okt[-c(outliers),] is removing random points in the data series, some of them are outliers and others are not.

What you can do is use the output from the boxplot's stats information to retrieve the end of the upper and lower whiskers and then filter your dataset using those values. See the example below:

#test data
testdata<-iris$Sepal.Width

#return boxplot object
b<-boxplot(testdata)

#find extremes from the boxplot's stats output
lowerwhisker<-b$stats[1]
upperwhisker<-b$stats[5]

#remove the extremes
testdata<-testdata[testdata>lowerwhisker & testdata<upperwhisker]

#replot
b<-boxplot(testdata)
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!