Say I have a list containing vectors of factors:
colors <- c("red", "green", "blue")
f <- factor(colors, levels=colors)
rgb <- sapply(sample(1:3, 5, replace=TRUE), function(n) sample(f, n))
Which might look like this:
> invisible(sapply(rgb, function(x) print(x, max.levels=0)))
[1] blue green
[1] red
[1] blue red green
[1] red blue green
[1] blue
How can I construct a matrix of indicator values that represent the same information:
[,1] [,2] [,3]
[1,] 0 1 1
[2,] 1 0 0
[3,] 1 1 1
[4,] 1 1 1
[5,] 0 0 1