Skip to content

Instantly share code, notes, and snippets.

@nachocab
Created September 8, 2015 17:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nachocab/6cc9841be1b070517bb9 to your computer and use it in GitHub Desktop.
Save nachocab/6cc9841be1b070517bb9 to your computer and use it in GitHub Desktop.
my_factor <- factor(c("a", "b", "c", "b", "c"), levels = c("c", "b", "a"))
model.matrix(~my_factor) # smyth's way
m <- model.matrix(~ 0 + my_factor) # my way
colnames(m) <- levels(my_factor)
makeContrasts(average_levels = (a + b +c)/3,
b_vs_a = b - a, levels = m)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment