A_D
A_D

Reputation: 705

How to apply the resulting removed outliers on the dataset using boxplot

Good day,

I am using boxplot to remove the outliers from my dataset:

outliers <- boxplot(dataset, outline=FALSE);

Now as outliers variable has all information, how do I apply the removal on dataset? Does boxplot do that inplace?

Thank you,

Upvotes: 0

Views: 44

Answers (2)

Prasanna Nandakumar
Prasanna Nandakumar

Reputation: 4335

Can use this -

x[!x %in% boxplot.stats(x)$out]

Upvotes: 0

neilfws
neilfws

Reputation: 33772

The values that boxplot considers to be outliers are stored in outliers$out. So, assuming that your dataset contains values in a column named value, you could remove them like this:

dataset[!dataset$value %in% outliers$out, ]

or if dataset had only the one column:

dataset[!dataset$value %in% outliers$out, , drop = FALSE]

Upvotes: 1

Related Questions