Description Usage Arguments Details Author(s) Examples
Convert a list of vectors into an indicator matrix
1 | list2matrix(mylist, count = FALSE)
|
mylist |
List to convert to matrix |
count |
Do want a full count of items, or just an indicator matrix? Default value is FALSE; meaning just an indicator matrix. |
Converts a list of vectors into an indicator matrix that spans the universe of the list elements. Add count = TRUE to show how many times each item appears in each list element, otherwise it's a 1 or 0 indicator matrix.
This is optimized for large matricies when count = FALSE. The count feature should slow things down a bit for large data sets.
Gene Leynes
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | ## Imagine you had shoppers who had bought multiple items, sometimes in
## multiples, and you wanted to pass the times into a model as a matrix.
ex <- list(ShopperNo1 = c("tomatoes", "apples", "oranges", "apples"),
ShopperNo2 = c("watermellons", "apples", "mangos", "mangos", "mangos"),
ShopperNo3 = c("carrots", "watermellons"),
ShopperNo4 = c("mangos", "mangos", "mangos", "mangos"),
ShopperNo5 = c("mangos"))
ex
## Indicator matrix (fast on large data sets)
list2matrix(ex)
## Count matrix shows how many times something occurred, not just if
## it occurred
list2matrix(ex, count = TRUE)
## This example is more confusing, but it can be interesting and useful to
## see package dependencies, espeically if you have a lot of interdependent
## packages loaded such as ggplot2, reshape2, data.table
deplist <- dependencylist(standard_packages = "")
list2matrix(deplist)
deplist
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.