Convert list to incidence matrix
list2im(x, makeUnique = TRUE, verbose = FALSE, ...)
x | list of character vectors. |
---|---|
makeUnique | logical indicating whether to enforce uniqueness on
each vector in the list. If |
verbose | logical indicating whether to print verbose output. |
This function uses some very efficient methods from the arules
package to convert a list of items into an incidence matrix.
The conversion creates a transactions
object, which takes
advantage of the efficient code, then extracts the matrix from
that object. Unfortunately, that object class does not permit
counting each item, though it may be possible through another
method.
The incidence matrix will have rownames matching list elements, and colnames match the list names.
In future the uniqueness step may be carried out using
S4Vectors
list methods, which are also highly efficient
specifically in handling very large lists.
Other jam list functions:
intercalate()
set.seed(123); l1 <- list(first=sample(letters, 10), second=sample(letters, 15), third=sample(letters, 5)); list2im(l1);#> first second third #> a 0 1 0 #> c 1 1 0 #> d 0 1 0 #> e 1 1 0 #> g 0 1 1 #> h 0 1 0 #> i 0 1 1 #> j 1 1 1 #> k 1 1 0 #> l 0 1 0 #> m 0 0 1 #> n 1 1 0 #> o 1 0 1 #> r 1 0 0 #> s 1 1 0 #> u 0 1 0 #> x 1 1 0 #> y 1 1 0