list2im_value: Convert list to a value incidence matrix

list2im_valueR Documentation

Convert list to a value incidence matrix

Description

Optimized conversion of list to a value incidence matrix

Usage

list2im_value(
  setlist,
  empty = NULL,
  do_sparse = FALSE,
  force_sign = FALSE,
  ...
)

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 "ngCMatrix" from the Matrix package.

...

additional arguments are ignored.

coerce_sign

logical indicating whether to coerce numeric vector values to the sign. When coerce_sign=FALSE the vector values are stored directly. When coerce_sign=TRUE the signs of the vector values are stored.

Details

This function converts a list of named vectors into an incidence matrix with value for each entry (row) present in each input list (column). This output is called a "value incidence matrix" because the value itself is included in the matrix as opposed to a true incidence matrix that represents only TRUE or FALSE (1 or 0) at each position.

The rownames of the output matrix represent items, encoded by the vector names. The colnames of the output matrix represent the list names.

The default value in the output matrix is 0 for a numeric matrix, and "" for a character matrix, based on the input vector classes.

To override this behavior, use the argument empty. For example, it may be useful to encode missing entries as NA, which means "this entry was not observed", and store true values of 0 to indicate "this entry was observed and its value was 0 zero". In this case use empty=NA.

This behavior can be useful with gene expression data, when a particular gene may not be observed in all data sets.

Value

Matrix object that contains signed direction encoded as c(-1, 0, 1) values.

See Also

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

Examples

setlist <- make_venn_test(100, 3, do_signed=TRUE)
imv <- list2im_value(setlist);
print(head(imv));

# convert back to list
im_value2list(imv);

# example showing empty=NA
setlist2 <- make_venn_test(20, 3, sizes=c(12, 14, 8), do_signed=TRUE)
setlist2 <- lapply(setlist2, function(i){
   i[] <- sample(c(-1, 0, 1),
      replace=TRUE,
      size=length(i));
   i
})
imv2 <- list2im_value(setlist2, empty=NA);
imv2;

# to convert back to list, define empty=NA so 0 is not considered as empty
im_value2list(imv2, empty=NA);

# make a simple character vector list
setlistv <- lapply(setlist, function(i){
   j <- letters[i+3];
   names(j) <- names(i);
   j;
})
imv <- list2im_value(setlistv);
print(head(imv));

# convert back to list of character vectors
im_value2list(imv);


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