matrix2xyz | R Documentation |
These are functions to convert between different matrix formats. Generally, we may convert a two-dimensional
array of values to a linear xyz format which contains the coordinates or indices of the rows and columns
corresponding to each matrix element z
.
matrix2xyz(m, na.rm = FALSE)
xyz2matrix(x, y, z, fun)
m |
Matrix. |
na.rm |
Logical value specifying whether to remove |
x |
Vector containing matrix row indices. Alternatively, |
y |
Vector containing the matrix column indices. Must be the same length as |
z |
Vector containing the matrix elements which are mapped by |
fun |
Function (e.g. |
Matrix
matrix2xyz()
: Convert from matrix to xyz format.
xyz2matrix()
: Convert from xyz to matrix format.
# Define random matrix:
m <- round(matrix(runif(40), nrow = 8), 2)
# Convert to XYZ format:
v <- matrix2xyz(m)
# Convert back to matrix format:
xyz2matrix(x = v[,"x"], y = v[,"y"], z = v[,"z"])
# Equivalently:
xyz2matrix(v)
# Convert XYZ elements with duplicate entries to matrix:
x <- c(1, 1, 3, 2, 3)
y <- c(2, 2, 1, 2, 3)
z <- 1:5
m <- xyz2matrix(x, y, z, mean)
# Convert back to XYZ format:
v <- matrix2xyz(m, na.rm = TRUE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.