I have a data frame of many columns. First column is the ID, second is age group (below 30, 30-40, 40-50, etc.), and the rest of the columns are Q1, Q2, Q3...Q50 with integer values and NA. I need to count the non-NA values for each column by age group.
I tried this and the "n" in the last line of the codes is not working, but if I replace "n" with "mean", it works well.
library(dplyr) df2 <- df %>% group_by(age_grp) %>% summarise_if(is.integer, n, na.rm=TRUE)
Thanks.