samedi 1 août 2020

using ifelse to remove outliers

I would like to remove outliers based on the function below, that is xhigh values.

   low <- median(x, na.rm=TRUE)-5*(mad(x)) 
   high <- median(x, na.rm=TRUE)+5*(mad(x))   
   out <- if_else(x > high, NA_real_,ifelse(x < low, NA_real_, x)) 
   out }

values of x>high were replaced with NA, but x<low were retained in the dataset. How should I modify the function?

Aucun commentaire:

Enregistrer un commentaire