Learn R Programming

mcstatsim (version 0.5.0)

combine_df: Combine Dataframes in a Nested List

Description

This function combines dataframes that are nested within a list of lists into a single dataframe.

Usage

combine_df(nested_list)

Value

A combined dataframe where each original dataframe is augmented with an ID column indicating its source list.

Arguments

nested_list

A list of lists, where each sublist contains dataframes to be combined.

Details

The function first checks if the input is a non-empty list of lists containing dataframes. It then iterates through each sublist, combining the dataframes and adding an ID column to indicate their source. Finally, all combined dataframes are row-bound into a single dataframe.

Examples

Run this code
df1 <- data.frame(a = 1:3, b = 4:6)
df2 <- data.frame(a = 7:9, b = 10:12)
nested_list <- list(list(df1, df2), list(df1, df2))
combine_df(nested_list)

Run the code above in your browser using DataLab