We can use across with summarise

library(dplyr)
library(broom)
out <- sampled_df %>% 
   summarise(across(all_of(numerical_columns), 
     ~list(cor.test(., categorical_column) %>% 
             tidy %>% 
             select(estimate, p.value))))

unclass(out) %>%
      bind_rows(.id = 'grp')
# A tibble: 2 x 3
#  grp   estimate p.value
#  <chr>    <dbl>   <dbl>
#1 1        0.408   0.495
#2 2        0.343   0.572

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top