dMcast | R Documentation |
data frame
into a wide sparse matrixSimilar in function to dcast
, but produces a sparse
Matrix
as an output. Sparse matrices are beneficial for this
application because such outputs are often very wide and sparse. Conceptually
similar to a pivot
operation.
dMcast(
data,
formula,
fun.aggregate = "sum",
value.var = NULL,
as.factors = FALSE,
factor.nas = TRUE,
drop.unused.levels = TRUE
)
data |
a data frame |
formula |
casting |
fun.aggregate |
name of aggregation function. Defaults to 'sum' |
value.var |
name of column that stores values to be aggregated numerics |
as.factors |
if TRUE, treat all columns as factors, including |
factor.nas |
if TRUE, treat factors with NAs as new levels. Otherwise, rows with NAs will receive zeroes in all columns for that factor |
drop.unused.levels |
should factors have unused levels dropped? Defaults to TRUE,
in contrast to |
Casting formulas are slightly different than those in dcast
and follow
the conventions of model.matrix
. See formula
for
details. Briefly, the left hand side of the ~
will be used as the
grouping criteria. This can either be a single variable, or a group of
variables linked using :
. The right hand side specifies what the
columns will be. Unlike dcast
, using the +
operator will append
the values for each variable as additional columns. This is useful for
things such as one-hot encoding. Using :
will combine the columns as
interactions.
a sparse Matrix
cast
dcast
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.