ldf_to_df: Transform list of data.frames to a data.frame.

ldf_to_dfR Documentation

Transform list of data.frames to a data.frame.

Description

Combines a split data.frame back to the original. This wraps data.table's rbindlist function.

Usage

ldf_to_df(
  list,
  add_by = T,
  by_name = "group",
  rownames_to_var = F,
  rownames_name = "rownames",
  messages = T
)

Arguments

list

(list of data.frames) The data.frames.

add_by

(log scalar) Whether to add a variable indicating the origin of each row.

by_name

(chr scalar) What should the added variable by called? Only used when add_by = TRUE.

rownames_to_var

(log scalar) Should rownames be saved in a variable? (Default no)

rownames_name

(log scalar) The variable name to save rownames under. Only used if rownames_to_var = TRUE.

Examples

#simple example: split iris by species, then recombine
all(ldf_to_df(df_to_ldf(iris, by = "Species")) == iris) #all identical

#complex example: same as above but delete some columns
iris_set = iris[iris$Species == "setosa", -c(1, 5)] #create 3 lists with partly missing columns
iris_ver = iris[iris$Species == "versicolor", -c(2, 5)]
iris_vir = iris[iris$Species == "virginica", -c(3, 5)]
iris_list = list("setosa" = iris_set, "versicolor" = iris_ver, "virginica" = iris_vir) #a combined list
#then merge to one data.frame
ldf_to_df(iris_list) #note the missing data and column order

Deleetdk/kirkegaard documentation built on April 22, 2024, 5:22 p.m.