library(tidyverse)
(result_df <- summarise_if(iris,
is.numeric,
~ list(quantile(x = .,
probs = c(0.01, 0.99)))))
# for display purposes ; the top and bottom 1% cut offs per variable
result_df %>% unnest(cols = everything())
#now get the actual values found
#first low then high
low_1 <- map2(
.x = names(result_df),
.y = result_df,
.f = ~ filter(iris, !!sym(.x) <= (.y %>% unlist() %>% .[[1]])) %>% pull(
.x
)
)
names(low_1) <- names(result_df)
low_1
high_99 <- map2(
.x = names(result_df),
.y = result_df,
.f = ~ filter(iris, !!sym(.x) >= (.y %>% unlist() %>% .[[2]])) %>% pull(
.x
)
)
names(high_99) <- names(result_df)
high_99