我正在尝试从我的数据集中删除异常值,但我似乎没有工作。我已经在数字向量上测试了这种技术并且它有效。但是,当尝试将其应用于来自 csv 文件的数据集时。它似乎没有任何作用。是我做错了什么还是我完全错误地处理异常值?
测试 CSV 文件数据
vehicles <- read.csv("C:/Users/Documents/vehiclescsv.csv") #load csv file
vehicles2 <- vehicles[,-1] #remove first column "Sample" number
vehicles3 <- vehicles2[,-19] #remove final column "Class" name
vehData <- vehicles3
vehClass <- vehicles$Class #store final column, class name
boxplot(vehData) #plot data to see outliers
OutVals <- boxplot(vehData)$out #find and store outliers
OutVals
vehDataRemoveOut <- vehData[!(vehData%in%OutVals)] #remove the outliers
length(vehData) - length(vehDataRemoveOut)# see if outliers have been removed
boxplot(vehDataRemoveOut) #re-plot to see changes
向量测试
x <- c(10,20,30,40,50,1000)
boxplot(x)
OutVals <- boxplot(x)$out
OutVals
RemovedOut <- x[!(x %in%OutVals)]
length(x) - length(RemovedOut)
boxplot(RemovedOut)
用于测试 dput(head()) 的数据 - 根据要求
vehData <-
structure(
list(
Samples = 1:6,
Comp = c(95L, 91L, 104L, 93L, 85L,
107L),
Circ = c(48L, 41L, 50L, 41L, 44L, 57L),
D.Circ = c(83L,
84L, 106L, 82L, 70L, 106L),
Rad.Ra = c(178L, 141L, 209L, 159L,
205L, 172L),
Pr.Axis.Ra = c(72L, 57L, 66L, 63L, 103L, 50L),
Max.L.Ra = c(10L,
9L, 10L, 9L, 52L, 6L),
Scat.Ra = c(162L, 149L, 207L, 144L, 149L,
255L),
Elong = c(42L, 45L, 32L, 46L, 45L, 26L),
Pr.Axis.Rect = c(20L,
19L, 23L, 19L, 19L, 28L),
Max.L.Rect = c(159L, 143L, 158L, 143L,
144L, 169L),
Sc.Var.Maxis = c(176L, 170L, 223L, 160L, 241L, 280L),
Sc.Var.maxis = c(379L, 330L, 635L, 309L, 325L, 957L),
Ra.Gyr = c(184L,
158L, 220L, 127L, 188L, 264L),
Skew.Maxis = c(70L, 72L, 73L,
63L, 127L, 85L),
Skew.maxis = c(6L, 9L, 14L, 6L, 9L, 5L),
Kurt.maxis = c(16L,
14L, 9L, 10L, 11L, 9L),
Kurt.Maxis = c(187L, 189L, 188L, 199L,
180L, 181L),
Holl.Ra = c(197L, 199L, 196L, 207L, 183L, 183L),
Class = c("van", "van", "saab", "van", "bus", "bus")
),
row.names = c(NA,
6L), class = "data.frame")
答案 0 :(得分:1)