unragMatrix | R Documentation |
This function turns a "ragged" matrix into a vector. Consider a case where you have a matrix that looks like:
1, 0, 1
2, 3, NA
NA, 4, NA
Here, each row represents a series of values, where missing values are represented by NA
. This can be turned into a vector form going from left to right and top to bottom of the matrix, as in c(1, 0, 1, 2, 3, 4)
, plus a vector c(1, 4, 6)
, which provides the index of the first non-NA
value in each row of the matrix in the vector, plus another vector, c(1, 1, 1, 2, 2, 3)
, indicating the row to which each value in the vector belonged.
unragMatrix(x, skip = NA)
x |
A matrix. |
skip |
|
A list with one vector per matrix, plus 1) a vector named startIndex
with indices of start values, and 2) a vector named row
with one value per non-skip
value in each matrix.
# default
x <- matrix(c(1, 0, 1, 2, 3, NA, NA, 4, NA), byrow = TRUE, nrow = 3)
unragMatrix(x)
# skip nothing
unragMatrix(x, skip = NULL)
# skips rows with all "skip" values
y <- matrix(c(1, 0, 1, NA, NA, NA, NA, 4, NA), byrow = TRUE, nrow = 3)
unragMatrix(y)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.