Flexible dummy-coding allowing for all R's built-in types of contrasts and optional dropping of a factor level to reduce rank defficiency probability.
dummycode(Y, contrast = "contr.sum", drop = TRUE)
vector
to dummy code.
Contrast type, default = "contr.sum".
logical
indicating if one level should be dropped (default = TRUE).
matrix
made by dummy-coding the input vector.
vec <- c("a","a","b","b","c","c")
dummycode(vec)
#> x1 x2
#> 1 1 0
#> 2 1 0
#> 3 0 1
#> 4 0 1
#> 5 -1 -1
#> 6 -1 -1