list2im | R Documentation |
convert list to incidence matrix
list2im(x, keepCounts = FALSE, emptyValue = 0, verbose = FALSE, ...)
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 |
verbose |
boolean indicating whether to print verbose output. |
... |
additional arguments are ignored. |
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.
numeric matrix whose rownames were vector items of the input list, and whole colnames were list names.
Other jam list functions:
colors_from_list()
,
im2list_dep()
,
im2list()
,
imSigned2list_dep()
,
imSigned2list()
,
list2concordance()
,
list2imSigned()
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);
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.