grading <- data.frame(
teacher = factor(c("Amy", "Amy", "Ben", "Ben", "Cat")),
gender = factor(c("male", "female", "female", "male", "male")),
grade = c(75, 80, 45, 50, 65)
)
# expand using the default contrasts (treatment contrasts)
expandFactors(grading)
# specify different contrasts via contrasts.arg
my.contrasts <- list(teacher = "contr.helmert", gender = "contr.treatment")
expandFactors(grading, contrasts.arg = my.contrasts)
Run the code above in your browser using DataLab