Description Usage Arguments Details Value See Also Examples
Create a selector matrix from a list of categories.
1 | selector_matrix(x, v, sparse = FALSE)
|
x |
A list of vectors used for indexing (i.e., a list of integer positions, names, or logical values). |
v |
An object that can be indexed with |
sparse |
Should the result be a sparse matrix from Matrix? |
This function is essentially an application of lapply
to a list of vectors for indexing that returns a matrix, the ij-th column of which has a 1 if the i-th element of x
selects the j-th element of v
, 0 otherwise.
The canonical application of this function has a numeric vector for v
so that the resulting selector matrix can be multiplied with v
to create a matrix where each column contains only certain values of v
.
An error is returned if any element of x
indexes out of the bounds of v
. This ensures that a matrix can be safely returned.
An integer matrix of 0's and 1's with a column for each element in x
and a row for each element in v
.
See pias_matrix
for a useful application when making a price index. See pias_class
for an easy way to build x
.
1 2 3 4 5 6 7 |
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.