im2list: convert incidence matrix to list

im2listR Documentation

convert incidence matrix to list

Description

convert incidence matrix to list

Usage

im2list(x, empty = c(NA, "", 0, FALSE), ...)

Arguments

x

matrix or equivalent object with colnames(x) indicating list set names, and rownames(x) indicating list contents.

empty

character vector of incidence matrix values that should be considered "empty" and therefore do not indicate the row in x is present for the given column in x. All other items are considered to be present.

...

additional arguments are ignored.

Details

This function converts an incidence matrix, or equivalent data.frame, to a list. The matrix should contain either numeric values such as c(0, 1), or logical values such as c(TRUE,FALSE), otherwise values are considered either zero == FALSE, or non-zero == TRUE.

The resulting list will be named by colnames(x) of the input, and will contain members named by rownames(x) which are either non-zero, or contain TRUE.

Values of NA are converted to zero 0 and therefore ignored.

Value

list of ⁠character vectors⁠, where list names are defined by colnames(x), and list elements are vectors that contain values from rownames(x).

See Also

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

Examples

im <- matrix(c(0,1,-1,1,1,NA,-1,0,1),
   ncol=3,
   nrow=3,
   dimnames=list(letters[1:3], LETTERS[1:3]))
print(im);
# matrix input
im2list(im);

# data.frame
imdf <- data.frame(im);
print(imdf);
im2list(im);

# logical input
imtf <- (!im == 0);
print(imtf);
im2list(imtf);


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