Convert a List of Sets to a Binary Matrix

list_to_matrix(lt, universal_set = NULL)

Arguments

lt

A list of vectors.

universal_set

The universal set.

Details

It converts the list which have m sets to a binary matrix with n rows and m columns where n is the size of universal set.

Examples

set.seed(123) lt = list(a = sample(letters, 5), b = sample(letters, 10), c = sample(letters, 15)) list_to_matrix(lt)
#> a b c #> c 1 1 0 #> d 0 0 1 #> e 0 1 1 #> g 0 0 1 #> h 0 0 1 #> i 0 1 1 #> j 1 0 1 #> k 0 1 1 #> l 0 0 1 #> m 0 0 1 #> n 1 1 1 #> o 1 0 0 #> q 0 0 1 #> r 0 1 0 #> s 1 1 1 #> t 0 1 0 #> v 0 1 1 #> w 0 1 0 #> x 0 0 1 #> y 0 0 1
list_to_matrix(lt, universal_set = letters)
#> a b c #> a 0 0 0 #> b 0 0 0 #> c 1 1 0 #> d 0 0 1 #> e 0 1 1 #> f 0 0 0 #> g 0 0 1 #> h 0 0 1 #> i 0 1 1 #> j 1 0 1 #> k 0 1 1 #> l 0 0 1 #> m 0 0 1 #> n 1 1 1 #> o 1 0 0 #> p 0 0 0 #> q 0 0 1 #> r 0 1 0 #> s 1 1 1 #> t 0 1 0 #> u 0 0 0 #> v 0 1 1 #> w 0 1 0 #> x 0 0 1 #> y 0 0 1 #> z 0 0 0