Matrix to List of (Atomic) Vectors
m2lv
converts a matrix to a list of (atomic) vectors. This is useful
since there is no as.list.matrix
method. When rownames and/or colnames
are NULL, they are replaced by their position numerals so that the dimension
information is retained.
m2lv(m, along, check = TRUE)
m |
matrix (i.e., array with 2 dimensions). |
along |
numeric vector of length 1 specifying which dimension to slice the matrix along. If 1, then the matrix is sliced by rows. If 2, then the matrix is sliced by columns. |
check |
logical vector of length 1 specifying whether to check the structure
of the input arguments. For example, check whether |
list of (atomic) vectors. If along
= 1, then the names are the
rownames of m
and the vectors are rows from m
. If along
= 2,
then the names are the colnames of m
and the vector are columns from m
.
Note, the vectors always have the same length as nrow(m)
.
m2lv(VADeaths, along = 1) m2lv(VADeaths, along = 2) m2lv(m = as.matrix(x = attitude, rownames.force = TRUE), along = 1) m2lv(m = as.matrix(x = attitude, rownames.force = TRUE), along = 2) m2lv(m = as.matrix(x = unname(attitude), rownames.force = FALSE), along = 1) # dimnames created as position numerals m2lv(m = as.matrix(x = unname(attitude), rownames.force = FALSE), along = 2) # dimnames created as position numerals # check = FALSE try_expr(m2lv(VADeaths, along = 3, check = FALSE)) # less informative error message try_expr(m2lv(VADeaths, along = 3, check = TRUE)) # more informative error message
Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.