d2ld {str2str}R Documentation

Data-Frame to List of Data-Frames

Description

d2ld converts a data.frame to a list of data.frames. This is a simple call to split.data.frame splitting the data.frame up by groups.

Usage

d2ld(
  d,
  by,
  keep.by = TRUE,
  drop = FALSE,
  sep = ".",
  lex.order = FALSE,
  check = TRUE
)

Arguments

d

data.frame.

by

character vector of colnames specifying the groups to split the data.frame up by. Can be multiple colnames, which implicitly calls interaction.

keep.by

logical vector of length 1 specifying whether the by columns should be kept in the list of data.frames (TRUE) or removed (FALSE).

drop

logical vector of length 1 specifying whether unused groups from the by columns should be dropped (TRUE) or kept (FALSE). This only applies when there are multiple by columns. drop = FALSE can then result in some data.frames with nrow = 0. See interaction for details.

sep

character vector of length 1 specifying the string used to separate the group names. Only applicable with multiple by columns. See interaction for details.

lex.order

logical vector of length 1 specifying the order of the data.frames in the list based on the groups in the by columns. This only applies when there are multiple by columns. See interaction for details.

check

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

Value

list of data.frames split by the groups specified in the by columns. The list names are the group names (with sep if there are multiple by columns).

Examples


# one grouping variable
d2ld(d = mtcars, by = "vs")
d2ld(d = mtcars, by = "gear")

# two grouping variables
d2ld(d = mtcars, by = c("vs","gear"))
d2ld(d = mtcars, by = c("vs","gear"), lex.order = TRUE)

# keep.by argument
d2ld(d = mtcars, by = "vs", keep.by = FALSE)
d2ld(d = mtcars, by = "gear", keep.by = FALSE)
d2ld(d = mtcars, by = c("vs","gear"), keep.by = FALSE)


[Package str2str version 1.0.0 Index]