How can we calculate the following from the example below using dplyr or other useful libraries:
- total number of schools by each state,
- total number of students by each school,
- total number of students by each school by Gender,
- total number of students by each school by Gender and type,
- mean of item1 and item3 by Gender,
- mean of item1 and item3 by Gender for each state,
ID = 1:50
states = rep(c("TS", "NE", "AR", "MO", "WA"),times = c(10, 10, 10, 10, 10))
schools = randomNames::randomNames(50) ## 5 first last names separated by a space
Gender = rep(c("male", "female"),times = c(18,32))
type = rep(c("private", "public"),times = c(20,30))
item1 = rnorm(50, mean=25, sd=5)
item2 = rnorm(50, mean=30, sd=5)
item3 = rnorm(50, mean=15, sd=5)
df = data.frame(ID, states, schools, Gender, type, item1, item2, item3)
df
Thanks so much in advance.