extract dataframe from list in r

To extract a data frame from a list in R, you can use indexing with double square brackets [[ and specify the name of the data frame you want to extract.

For example, let's say you have a list named my_list that contains two data frames named df1 and df2. Here's how you can extract df1:

main.r
# create a list with two data frames
df1 <- data.frame(a = 1:3, b = 4:6)
df2 <- data.frame(x = c("a", "b", "c"), y = c(7, 8, 9))
my_list <- list(df1 = df1, df2 = df2)

# extract df1 from the list using double square brackets
my_df <- my_list[["df1"]]
251 chars
8 lines

Now my_df contains the data frame df1.

gistlibby LogSnag