Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

cast_sparse

Create a sparse matrix from row names, column names, and values in a table.


Description

This function supports non-standard evaluation through the tidyeval framework.

Usage

cast_sparse(data, row, column, value, ...)

Arguments

data

A tbl

row

Column name to use as row names in sparse matrix, as string or symbol

column

Column name to use as column names in sparse matrix, as string or symbol

value

Column name to use as sparse matrix values (default 1) as string or symbol

...

Extra arguments to pass on to sparseMatrix

Details

Note that cast_sparse ignores groups in a grouped tbl_df. The arguments row, column, and value are passed by expression and support quasiquotation; you can unquote strings and symbols.

Value

A sparse Matrix object, with one row for each unique value in the row column, one column for each unique value in the column column, and with as many non-zero values as there are rows in data.

Examples

dat <- data.frame(a = c("row1", "row1", "row2", "row2", "row2"),
                  b = c("col1", "col2", "col1", "col3", "col4"),
                  val = 1:5)

cast_sparse(dat, a, b)

cast_sparse(dat, a, b, val)

tidytext

Text Mining using 'dplyr', 'ggplot2', and Other Tidy Tools

v0.3.1
MIT + file LICENSE
Authors
Gabriela De Queiroz [ctb], Colin Fay [ctb] (<https://orcid.org/0000-0001-7343-1846>), Emil Hvitfeldt [ctb], Os Keyes [ctb] (<https://orcid.org/0000-0001-5196-609X>), Kanishka Misra [ctb], Tim Mastny [ctb], Jeff Erickson [ctb], David Robinson [aut], Julia Silge [aut, cre] (<https://orcid.org/0000-0002-3671-836X>)
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.