How to remove outliers from a data array in R

683 Views Asked by At

I would like to locate and remove the outlier in the measurement and replace with a smoothened value to capture the trend better. Please find the figure below Data with outliers

1

There are 1 best solutions below

0
On

You need the function smooth.

Example:

y = seq(61,68,0.5)
x = 1:15
y[7]= 59

D = data.frame(x,y)
ys = smooth(y)
Ds = data.frame(x,ys)

par(mfrow=c(1,2))
plot(D, type="b", main="Original Data")
plot(Ds, type="b", main="Smoothed Data")

Smoothed Data