factor 変数の場合
> fac = factor(c("c", "a", "b", "b", "a", "c", "b"))
> z = levels(fac)
> t(sapply(fac, function(x) z %in% x))[, -1] + 0
[,1] [,2]
[1,] 0 1
[2,] 0 0
[3,] 1 0
[4,] 1 0
[5,] 0 0
[6,] 0 1
[7,] 1 0
数値変数の場合
> num = c(1, 3, 2, 1, 3, 3, 2)
> z = as.numeric(names(table(num)))
> t(sapply(num, function(x) z %in% x))[, -1] + 0 # factor 変数の場合と同じ
[,1] [,2]
[1,] 0 0
[2,] 0 1
[3,] 1 0
[4,] 0 0
[5,] 0 1
[6,] 0 1
[7,] 1 0