0

I want to check the outlier value of each variable in R and change the outlier value of the variable to a specific value.

Many people have written in stackoverflow to recommend the outlierTest function in the car package.

The outlierTest function, however, extracted the result of a particular row, not variable.

I want a variable to have an outlier and to change that value to a specific value. What functions and code should I use?

+Here is my data code. It it open source. So you can load that data as following code.

credit<-read.csv("http://freakonometrics.free.fr/german_credit.csv", header=TRUE)
F=c(1,2,4,5,7,8,9,10,11,12,13,15,16,17,18,19,20,21)
for(i in F) credit[,i]=as.factor(credit[,i])
이순우
  • 79
  • 1
  • 1
  • 10

2 Answers2

0

You have got several options to detect and change outliers. Please check this really helpfull post:

https://www.r-bloggers.com/outlier-detection-and-treatment-with-r/

Koot6133
  • 1,428
  • 15
  • 26
0

Finding outlier and replacing it with 99th percentile value

Data_Outlier <- read.csv(file.choose()) # Your dataset
percentile.table = data.frame(NULL)

for(i in 2:ncol(Data_Outlier))
 {      
     if (is.numeric(Data_Outlier[,i]))
     {
         percentile_value <- quantile(Data_Outlier[,i],c(0.99),na.rm=TRUE)
         Variable = names(Data_Outlier)[i]
         Percentile.99 = percentile_value
         table = cbind(Variable, Percentile.99)
         percentile.table = rbind(percentile.table,table)
     }
 }
print(percentile.table,row.names=FALSE)

for(i in 2:ncol(Data_Outlier))
 {
     Percentile.99 = quantile(Data_Outlier[,i],c(0.99),na.rm=TRUE)
     Data_Outlier[,i][Data_Outlier[,i]>Percentile.99] = Percentile.99
 }
Prasanna Nandakumar
  • 4,295
  • 34
  • 63