This function wraps purrr::reduce() and dplyr::full_join() to reduce all or some dataframes in a list into a single dataframe.

list_df(lst, df_names = NULL, by = NULL)

Arguments

lst

A list of dataframes.

df_names

Names of the list elements to join. NULL defaults to use all list elements.

by

A character vector of variables to join by. If NULL, the default, *_join() will do a natural join, using all variables with common names across the two tables. To join by different variables on x and y use a named vector. For example, by = c("a" = "b") will match x.a to y.b. Passed to dplyr::full_join()

Value

A dataframe.

See also

purrr::reduce() and dplyr::full_join().

Other general functions to export data: list_csv

Examples

dfs <- list( a = data.frame(x = 1), b = data.frame(x = 2, y = 2), c = data.frame(x = 1, z = 3) ) list_df(dfs)
#> x y z #> 1 1 NA 3 #> 2 2 2 NA
list_df(dfs, df_names = c("a", "c"))
#> x z #> 1 1 3
list_df(dfs, df_names = c("b", "c"))
#> x y z #> 1 2 2 NA #> 2 1 NA 3
# Use argument `by` if dataframes have no matching variable, list_df( list(data.frame(x = 1), data.frame(z = 2)), by = c("x" = "z") )
#> x #> 1 1 #> 2 2