Error in .subset2(x, i, exact = exact) : subscript out of bounds in R

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

1 thought on “Error in .subset2(x, i, exact = exact) : subscript out of bounds in R”

  1. This is a different sort of opinion that many people dont usually talk about. Sometimes I fav stuff like this on Redit. Although this time Im not sure if this would be best for the users. Ill take a look around your site though and submit something else.

    Reply

Leave a Comment