Search code examples
rrows

How to get all the rows to show?


I'm trying to get a summary of a variable grouped by two other variables and I want all the rows to show. How do I do that?

The code I'm using is:

usl %>%    group_by(ethnicity_fct, harassment_fct) %>%   
summarise(mean_menthealth = mean(menthealth, na.rm = T),
           menthealth_var = var(menthealth, na.rm = T))

Also, is there a way so that NA does not appear? Table1


Solution

  • Try to continue the pipe with na.omit to remove the NA's and print.data.frame to override the print method for tibbles.

    usl %>% 
      group_by(ethnicity_fct, harassment_fct) %>%   
      summarise(mean_menthealth = mean(menthealth, na.rm = T),
                menthealth_var = var(menthealth, na.rm = T)) %>%
      na.omit() %>%
      print.data.frame()