I feel like this should be obvious but I'm struggling. Across function doesn't work since I'm not trying to mutate.
I want the rate to be calculated on a df of a bunch of students based on different demographic details. I know this is not a reproducible example but It should be clear enough like this.
The first function will give the rate for a demographic detail when you give the column name and the df. The second function, goes through a series of demographic columns and binds them together. I really want a function where I don't need to list all the demographic columns and it will just go through All:Homeless and do all of them and skip any missing ones.
Thanks.
car.school <- function(df,students) {
ddff <- deparse(substitute(df))
studentsss <- deparse(substitute(students))
holder <- df %>%
ungroup() %>%
filter({{students}} == "Yes") %>%
mutate( # dist.standard = ScaleScore - MeetStandard,
chronic.rate = 100*mean(chronic),
count = n()) %>%
select(chronic.rate, count) %>%
distinct() %>%
mutate(district = ddff,
students = studentsss
)
# sheet_append(ss = sheet,
# sheet = "Distance from Standard Group",
# data = holder )
holder
}
add.school.car <- function(df) {
namer <- unique(df$SchoolName)
coder <- unique(df$SchoolCode)
waiting.room <- car.school(df,All) %>%
bind_rows( car.school(df,White) ) %>%
bind_rows( car.school(df,EnglishLearner) ) %>%
bind_rows( car.school(df,Asian) ) %>%
bind_rows( car.school(df,Filipino) ) %>%
bind_rows( car.school(df,Multiple) ) %>%
bind_rows( car.school(df,`Black/African Am`) ) %>%
bind_rows( car.school(df,`Am Indian/Alskn Nat`) ) %>%
bind_rows( car.school(df,`Nat Hwiin/Othr Pac Islndr`) ) %>%
bind_rows( car.school(df,Hispanic) ) %>%
bind_rows( car.school(df,StudentswithDisabilities) ) %>%
bind_rows( car.school(df,SocioEconomicallyDisadvantaged) ) %>%
bind_rows( car.school(df,Homeless) ) %>%
mutate(SchoolName = namer,
SchoolCode = coder
)
waiting.room
}