Skip to contents

Value incidence matrix to list

Usage

im_value2list(x, empty = c(NA, "", 0), ...)

Value

list whose names are set names derived from colnames(x), and where each vector is named using rownames(x) and the values from x, for non-empty values.

Details

This function is the reciprocal to list2im_value().

A value incidence matrix is a matrix whose non-empty values are retained in each item vector, where items are stored as vector names.

This function is most commonly used with signed values c(-1, 0, 1), to indicate direction where 1 is up, -1 is down, and 0 is not changed. In this case 0 which is considered empty by default.

See also

Examples

setlist <- make_venn_test(100, 3, do_signed=TRUE)
ims <- list2im_value(setlist);
print(head(ims));
#>          set_A set_B set_C
#> item_067    -1     0     0
#> item_042     1     0     0
#> item_050     1     0    -1
#> item_043    -1     0     0
#> item_014    -1     0     0
#> item_025     1    -1     0

# convert back to list
im_value2list(ims);
#> $set_A
#> item_067 item_042 item_050 item_043 item_014 item_025 item_090 item_091 
#>       -1        1        1       -1       -1        1       -1       -1 
#> item_069 item_093 item_057 item_009 item_072 item_026 item_007 item_099 
#>       -1        1        1       -1        1        1       -1       -1 
#> item_089 item_083 item_036 item_078 item_097 item_076 item_015 item_032 
#>       -1        1        1        1        1        1       -1        1 
#> item_086 item_084 item_041 item_023 item_027 item_060 item_053 item_079 
#>        1        1       -1        1       -1        1        1       -1 
#> 
#> $set_B
#> item_025 item_069 item_093 item_072 item_089 item_097 item_076 item_027 
#>       -1       -1        1        1       -1       -1        1       -1 
#> item_053 item_096 item_038 item_034 item_063 item_013 item_082 item_021 
#>        1        1       -1       -1        1        1        1       -1 
#> 
#> $set_C
#> item_050 item_090 item_091 item_072 item_086 item_041 item_060 item_079 
#>       -1       -1        1        1        1       -1        1       -1 
#> item_047 item_095 item_016 item_006 item_039 item_031 item_081 
#>        1        1        1       -1        1       -1        1 
#> 

# 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));
#>          set_A set_B set_C
#> item_067 "b"   ""    ""   
#> item_042 "d"   ""    ""   
#> item_050 "d"   ""    "b"  
#> item_043 "b"   ""    ""   
#> item_014 "b"   ""    ""   
#> item_025 "d"   "b"   ""   
im_value2list(imv);
#> $set_A
#> item_067 item_042 item_050 item_043 item_014 item_025 item_090 item_091 
#>      "b"      "d"      "d"      "b"      "b"      "d"      "b"      "b" 
#> item_069 item_093 item_057 item_009 item_072 item_026 item_007 item_099 
#>      "b"      "d"      "d"      "b"      "d"      "d"      "b"      "b" 
#> item_089 item_083 item_036 item_078 item_097 item_076 item_015 item_032 
#>      "b"      "d"      "d"      "d"      "d"      "d"      "b"      "d" 
#> item_086 item_084 item_041 item_023 item_027 item_060 item_053 item_079 
#>      "d"      "d"      "b"      "d"      "b"      "d"      "d"      "b" 
#> 
#> $set_B
#> item_025 item_069 item_093 item_072 item_089 item_097 item_076 item_027 
#>      "b"      "b"      "d"      "d"      "b"      "b"      "d"      "b" 
#> item_053 item_096 item_038 item_034 item_063 item_013 item_082 item_021 
#>      "d"      "d"      "b"      "b"      "d"      "d"      "d"      "b" 
#> 
#> $set_C
#> item_050 item_090 item_091 item_072 item_086 item_041 item_060 item_079 
#>      "b"      "b"      "d"      "d"      "d"      "b"      "d"      "b" 
#> item_047 item_095 item_016 item_006 item_039 item_031 item_081 
#>      "d"      "d"      "d"      "b"      "d"      "b"      "d" 
#>