箱线法剔除离群值
2019-03-01 本文已影响5人
落寞的橙子
在实际应用中经常会用到剔除离群值的情况,本文提供箱线法剔除离群值的方法,仅限参考:
library(grid)
library(DMwR)
#setwd("C:/Users/Administrator.WIN7-1607161609/Desktop")
data<-read.csv("test.csv",header = T)
colnames<-colnames(data)
{
x<-data[,i]
x<-na.omit(x)
rnub<-c(1:length(x))
out1 <- boxplot.stats(x)
out <- boxplot.stats(x)$out
#boxplot(x)
#out.point <- matrix(c(which(x %in% out), x[which(x %in% out)]), ncol = 2)
outlier<-c(which(x %in% out))
row_without<-setdiff(rnub,outlier)
y<-as.matrix(x[row_without])
colnames(y)<-colnames[i]
filenames<-paste0(as.character(colnames[i]),"without_outlier",".csv")
write.csv(y,filenames,quote=F,row.names = F)
}