Sandeep
Sandeep

Reputation: 9

R outlier program

I want to write a program for removing the outliers from my data set. This code shows the outlier rows and column number but it does not delete them from my data set:

library(outliers)
out <- outlier(Practice_data[,2:4], logical=TRUE)
out <- cbind(FALSE, out)
Practice_data[which(out[,], TRUE)]
which(out[,], TRUE)

So how can I delete these outliers from my data set and save them in another new data file?

Upvotes: 0

Views: 209

Answers (1)

Sandipan Dey
Sandipan Dey

Reputation: 23129

If you want to remove the rows that contains at least one outlier, try the following (the outlier function will identify the outliers in each dimension for you, it will not remove them, you have to remove them explicitly):

library(outliers) 
out <- outlier(Practice_data[,2:4], logical=TRUE) 
indices <- which(rowSums(out) > 0)
Practice_data <- Practice_data[-indices, ]

Upvotes: 1

Related Questions