applying iqr filter on all columns in R using dplyr

3.8k Views Asked by At

filtering data of all columns between their IQRs. Tried using filter_all(df_name,IQR(.)), returns the same dataframe

1

There are 1 best solutions below

0
On

IQR returns a single value with the distance between the 25th and 75th quantiles. To get all the data that is within this range, it is better to just use the quantile function directly. Here is how you can do it with dplyr::filter

data <- tibble::tibble(x = rnorm(100))

data %>% 
  dplyr::filter(x > quantile(x, 0.25), 
                x < quantile(x, 0.75))