r - Making a list of zeros and ones from a large list -
i have large list looks this: 1 2 3 3 and need create list looks this: |------|------|------|------| | 1 | 1 | 0 | 0 | |------|------|------|------| | 2 | 0 | 1 | 0 | |------|------|------|------| | 3 | 0 | 0 | 1 | |------|------|------|------| | 3 | 0 | 0 | 1 | |------|------|------|------| i have tried using loops, , method detailed here: create mutually exclusive dummy variables categorical variable in r but because dataset large, run memory constraints. am thinking of using split, apply, combine technique, not able desired result. help appreciated! here ways: 1) outer gives matrix result: x <- c(1, 2, 3, 3) outer(x, unique(x), "==") + 0 giving: [,1] [,2] [,3] [1,] 1 0 0 [2,] 0 1 0 [3,] 0 0 1 [4,] 0 0 1 2) model.matrix gives matrix result. fx <- factor(x) model.matrix(~ fx + 0) giving: fx1 fx2 fx3 1 1 0 0 2 ...