list_to_dummy.Rd
Create a dummy matrix based on the elements of a list. Each column in the produced matrix is a dummy indicator.
list_to_dummy(alist)
a list of vectors
A matrix of dummy variables
# let's say you have a list like this
num_list = list(1:3, 4:5, 6:9)
# get dummy matrix
list_to_dummy(num_list)
#> [,1] [,2] [,3]
#> [1,] 1 0 0
#> [2,] 1 0 0
#> [3,] 1 0 0
#> [4,] 0 1 0
#> [5,] 0 1 0
#> [6,] 0 0 1
#> [7,] 0 0 1
#> [8,] 0 0 1
#> [9,] 0 0 1
# try with a list of strings
str_list = list(c("a","b","c"), c("d", "e"), c("f","g","h"))
list_to_dummy(str_list)
#> [,1] [,2] [,3]
#> [1,] 1 0 0
#> [2,] 1 0 0
#> [3,] 1 0 0
#> [4,] 0 1 0
#> [5,] 0 1 0
#> [6,] 0 0 1
#> [7,] 0 0 1
#> [8,] 0 0 1