arr_from_coo | R Documentation |
These function similarly to Matrix's utilities but is simpler and allows arbitrary baseline and handling of missing values. (It is also almost certainly much slower.) Also, since it is likely that operations will be performed on the elements of the array, their argument is first for easier piping.
arr_from_coo(x, coord, dim = lengths(dimnames), x0 = NA, dimnames = NULL)
arr_to_coo(X, x0, na.rm = FALSE)
x |
values of elements differing from the default. |
coord |
an integer matrix of their indices. |
dim |
dimension vector; recycled to |
x0 |
the default value. |
dimnames |
dimension name list. |
X |
an array. |
na.rm |
whether the |
If x0
is NA
, non-NA
elements are returned; if x0
is NULL
,
all elements are.
coo_to_arr()
returns a matrix or an array.
arr_to_coo()
returns a list with the following elements:
x |
the values distinct from |
coord |
a matrix with a column for each dimension containing
indexes of values distinct from |
dim |
the dimension vector of the matrix |
dimnames |
the dimension name list of the matrix |
m <- matrix(rpois(25, 1), 5, 5)
arr_to_coo(m, 0L)
stopifnot(identical(do.call(arr_from_coo, arr_to_coo(m, 0L)), m))
stopifnot(length(arr_to_coo(m, NULL)$x) == 25) # No baseline
m[sample.int(25L, 2L)] <- NA
m
arr_to_coo(m, 0L) # Return NAs
arr_to_coo(m, 0L, na.rm = TRUE) # Drop NAs
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.