could we make it work for proportions without first having the students recode the variable as 0/1? While there is some pedagogical value in having the students think about the fact that a proportion is a mean of a 0/1 variable, I feel like it is a bit of a hacky solution and it wouldn’t be hard to write the function so that it can work directly with factor variables as long as there are at most two levels.
From Andy: