R/list_output.R
list_df.Rd
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)
lst | A list of dataframes. |
---|---|
df_names | Names of the list elements to join. |
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 |
A dataframe.
purrr::reduce()
and dplyr::full_join()
.
Other general functions to export data: list_csv
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#> x z #> 1 1 3#> 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