ld2v {str2str}R Documentation

List of Data-Frames to (Atomic) Vector

Description

ld2v converts a list of data.frames to a (atomic) vector. This function is a combination of d2v 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

ld2v(
  ld,
  along = 2,
  use.listnames = TRUE,
  use.dimnames = TRUE,
  sep = "_",
  fct = "chr",
  chr = "chr",
  lgl = "int",
  order.lvl = "alphanum",
  decreasing = FALSE,
  na.lvl = FALSE,
  check = TRUE
)

Arguments

ld

list of data.frames. They do NOT have to have the same dimensions.

along

numeric vector of length one that is equal to either 1 or 2. 1 means that each data.frame in ld is split along rows (i.e., dimension 1) and then concatenated. 2 means that each data.frame in ld 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 ld 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 names based on the dimnames of the data.frame the element came from. If a data.frame within ld 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.

fct

character vector of length 1 specifying what factors should be converted to. There are three options: 1) "chr" for converting to character vectors (i.e., factor labels), 2) "int" for converting to integer vectors (i.e., factor codes), or 3) "fct" for keeping the factor as is without any changes.

chr

character vector of length 1 specifying what character vectors should be converted to. There are three options: 1) "fct" for converting to factors (i.e., elements will be factor labels), 2) "int" for converting to integer vectors (i.e., factor codes after first converting to a factor), or 3) "chr" for keeping the character vectors as is without any changes.

lgl

character vector of length 1 specifying what logical vectors should be converted to. There are four options: 1) "fct" for converting to factors (i.e., "TRUE" and "FALSE" will be factor labels), 2) "chr" for converting to character vectors (i.e., elements will be "TRUE" and "FALSE"), 3) "int" for converting to integer vectors (i.e., TRUE = 1; FALSE = 0), and 4) "lgl" for keeping the logical vectors as is without any changes.

order.lvl

character vector of length 1 specifying how you want to order the levels of the factor. The options are "alphanum", which sorts the levels alphanumerically (with NA last); "position", which sorts the levels by the position the level first appears; "frequency", which sorts the levels by their frequency. If any frequencies are tied, then the ties are sorted alphanumerically (with NA last).

decreasing

logical vector of length 1 specifying whether the ordering of the levels should be decreasing (TRUE) rather than increasing (FALSE).

na.lvl

logical vector of length 1 specifying if NA should be considered a level.

check

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

Details

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

If the columns of the data.frames in ld are not all the same typeof, then the return object is coerced to the most complex type of any data.frame column (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 ld.

Examples

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

[Package str2str version 1.0.0 Index]