dropping missing values while using dplyr group_by %>% summarise(??? = n())

pbp1920_clutch %>%
group_by(Offense) %>%
summarise('FG%' = mean(ShotOutcome, na.rm = TRUE), ShotOutcome = n())

This code calculates the mean of ShotOutcome without missing values, but counts the ShotOutcome with missing values included. I wanted to use na.rm = TRUE for ShotOutcome = n(), but it doesn't seem to work. Is there any way to drop missing values when counting the number of factors using group_by and summarise()?

sum(!is.na(ShotOutcome))

Hi @skyfall

You can remove the NAs earlier in your code:

pbp1920_clutch %>%
  drop_na(ShotOutcome) %>% 
  group_by(Offense) %>%
  summarise('FG%' = mean(ShotOutcome), ShotOutcome = n())

Thank you! It worked

Thank you! It worked.