list2im: convert list to incidence matrix

list2imR Documentation

convert list to incidence matrix

Description

convert list to incidence matrix

Usage

list2im(x, keepCounts = FALSE, emptyValue = 0, verbose = FALSE, ...)

Arguments

x

list of vectors

keepCounts

boolean indicating whether to return values indicating the number of occurrences of each item.

emptyValue

any single value that should be used for blank entries, by default zero 0. Use emptyValue=NA to return NA for missing entries.

verbose

boolean indicating whether to print verbose output.

...

additional arguments are ignored.

Details

This function converts a list of vectors into an incidence matrix, where the rows are the vector items and the columns are the list names. It uses an object from the arules package called arules::transactions which offers highly efficient methods for interconverting from list to matrix. The transactions class is itself an enhanced data matrix, which stores data using sparse matrix object type from the Matrix package, but also associates a data.frame to both the rows and columns of the matrix to offer additional row and column annotation, as needed.

Performance benchmarks showed high speed of converting a list to a matrix, but also that the resulting matrix was substantially smaller (5-20 times) then comparable methods producing a data matrix.

When argument keepCounts=TRUE, the method of applying counts only updates entries with multiple instances, which helps make this step relatively fast.

Value

numeric matrix whose rownames were vector items of the input list, and whole colnames were list names.

See Also

Other jam list functions: colors_from_list(), im2list_dep(), im2list(), imSigned2list_dep(), imSigned2list(), list2concordance(), list2imSigned()

Examples

L1 <- list(A=c("C","A","B","A"),
   D=c("D","E","F","D"),
   A123=c(1:8,3,5),
   T=LETTERS[7:9]);
# Default behavior is to make items unique
list2im(L1);

# Option to report the counts
list2im(L1, keepCounts=TRUE);


jmw86069/jamenrich documentation built on Nov. 6, 2024, 7:07 p.m.