list2im_opt: Optimized list to incidence matrix

list2im_optR Documentation

Optimized list to incidence matrix

Description

Optimized conversion of list to incidence matrix

Usage

list2im_opt(setlist, empty = 0, do_sparse = TRUE, ...)

Arguments

setlist

list of vectors

empty

default single value used for empty/missing entries, the default empty=0 uses zero for entries not present. Another alternative is NA.

do_sparse

logical indicating whether to coerce the output to sparse matrix class "CsparseMatrix" from the Matrix package.

...

additional arguments are ignored.

Details

This function rapidly converts a list of vectors into an incidence matrix whose rownames are items, and colnames are the names of the input list. The default output do_sparse=TRUE returns a logical matrix class ngCMatrix from the Matrix package. When do_sparse=FALSE the output is a matrix class with numeric values 0 and 1.

Note that the rows in the output matrix are not sorted, since the step of sorting item names may take several seconds when working with a list whose vectors contain millions of items. For sorted rows, the best remedy is to run this function, the re-order rownames afterward.

Value

matrix object with value c(0, 1) when do_sparse=FALSE (default), or when do_sparse=TRUE, returns a Matrix object class "CsparseMatrix" with logical values.

See Also

Other venndir conversion: counts2setlist(), im2list(), im_value2list(), list2im_value(), overlaplist2setlist(), signed_counts2setlist()

Examples

setlist <- list(A=c("one", "two", "three"),
   b=c("two", "one", "four", "five"));
list2im_opt(setlist);

list2im_opt(setlist, do_sparse=TRUE);


jmw86069/venndir documentation built on Sept. 26, 2023, 3:43 a.m.