lm2v {str2str}R Documentation

List of Matrices to (Atomic) Vector

Description

lm2v converts a list of matrices to a (atomic) vector. This function is a combination of m2v and lv2v. This function can be useful in conjunction with the boot::boot function when wanting to generate a statistic function that returns an atomic vector.

Usage

lm2v(
  lm,
  along = 2,
  use.listnames = TRUE,
  use.dimnames = TRUE,
  sep = "_",
  check = TRUE
)

Arguments

lm

list of matrices. They do NOT have to be the same typeof or have the same dimensions.

along

numeric vector of length one that is equal to either 1 or 2. 1 means that each matrix in lm is split along rows (i.e., dimension 1) and then concatenated. 2 means that each matrix in lm is split along columns (i.e., dimension 2) and then concatenated.

use.listnames

logical vector of length 1 specifying whether the returned vector should have names based on the list the element came from. If lm does not have names, use.listnames = TRUE will have the list positions serve as the list names (e.g., "1", "2", "3", etc.)

use.dimnames

logical vector of length 1 specifying whether the returned vector should have named based on the dimnames of the matrix the element came from. If a matrix within lm does not have dimnames, use.dimnames = TRUE will have the dimension positions serve as the dimnames (e.g., "1", "2", "3", etc.)

sep

character vector of length 1 specifying the string used to separate the listnames and dimnames from each other when creating the names of the returned vector.

check

logical vector of length 1 specifying whether to check the structure of the input arguments. For example, check whether lm is a list of matrices. This argument is available to allow flexibility in whether the user values informative error messages (TRUE) vs. computational efficiency (FALSE).

Details

When list.names and use.dimnames are both TRUE (default), the returned vector elements the following naming scheme: "[listname][sep][rowname][sep][colname]".

If the matrices in lm are not all the same typeof, then the return object is coerced to the most complex type of any matrix (e.g., character > double > integer > logical). See unlist for details about the hierarchy of object types.

Value

(atomic) vector with an element for each element from 'lm'.

Examples

lm <- list("numeric" = data.matrix(npk), "character" = as.matrix(npk))
# use.listnames = TRUE & use.dimnames = TRUE
lm2v(lm) # the first part of the name is the list names followed by the dimnames
# use.listnames = FALSE & use.dimnames = TRUE
lm2v(lm, use.listnames = FALSE) # only dimnames used,
   # which can result in repeat names
# use.listnames = TRUE & use.dimnames = FALSE
lm2v(lm, use.dimnames = FALSE) # listnames and vector position without any
   # reference to matrix dimensions
# use.listnames = FALSE & use.dimnames = FALSE
lm2v(lm, use.listnames = FALSE, use.dimnames = FALSE) # no names at all
# when list does not have names
lm <- replicate(n = 3, expr = as.matrix(attitude, rownames.force = TRUE), simplify = FALSE)
lm2v(lm) # the first digit of the names is the list position and
   # the subsequent digits are the matrix dimnames
lm2v(lm, use.listnames = FALSE) # no listnames; only dimnames used,
   # which can result in repeat names

[Package str2str version 1.0.0 Index]