0

I am trying to do 'summarise_all' for all columns using median and want to ignore null data using na.rm = T.

For example,

df_sector <- df %>% 
    group_by(Sector) %>% 
    summarise_all(mean, na.rm = T)

is working.

However,

df_sector <- df %>% 
    group_by(Sector) %>% 
    summarise_all(median, na.rm = T)

is not working.

Is there any way to summarise all columns using median and na.rm?

samsacat
  • 15
  • 2
  • 1
    `summarise_all(median, na.rm = T)` works fine for me (tested with `dplyr_1.0.10`). Maybe share a proper [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input that can be used to test and verify possible solutions. – MrFlick Dec 01 '22 at 20:44

1 Answers1

1

Instead of summarize_all try across

df %>% 
  group_by(Sector) %>% 
  summarise(across(
    .cols = everything(),
    .fns =  list(mean = ~mean(.,na = TRUE), median = ~median(.,,na = TRUE))))
Vinícius Félix
  • 8,448
  • 6
  • 16
  • 32