I have a data set with about a hundred variables, so the easiest way for me to get the means by group is as follows:
iris %>%
group_by(species) %>%
summarise_if(is.numeric, mean, na.rm=T)
However, I also want to know the N within each mean count as well. R does not accept n() inside summarise_if.
I could manually type out each variable like this, but I have hundred of variables so that won't work.
iris %>% group_by(Species) %>%
summarise(mean_sl = mean(Sepal.Length), mean_sw = mean(Sepal.Width),
mean_pl = mean(Petal.Length), mean_pw = mean(Petal.Width), n())
Any idea's how I can get the mean, as well as the N for each numeric variable in my dataset?