Search code examples
rdataframelistsplitdata-cleaning

Extracting dataframes inside a list in R


I have two dataframes that I had put into a list. How do I extract these dataframees into two seperate ones? The list name is new_dfs and the dataframes inside are new_3 and new_7. I want these two dataframes to be seperate. When I converted my list into a dataframe using new_dfs<-as.data.frame. It just made them into one dataframe. An example code will be appreciated.

> str(new_dfs)
List of 2
 $ new_3:'data.frame':  683 obs. of  3 variables:
  ..$ class          : Factor w/ 2 levels "benign","malignant": 1 1 1 1 1 2 1 1 1 1 ...
  ..$ bare nuclei    : int [1:683] 1 10 2 4 1 10 10 1 1 1 ...
  ..$ clump thickness: int [1:683] 5 5 3 6 4 8 1 2 2 4 ...
 $ new_7:'data.frame':  683 obs. of  7 variables:
  ..$ class                : Factor w/ 2 levels "benign","malignant": 1 1 1 1 1 2 1 1 1 1 ...
  ..$ bare nuclei          : int [1:683] 1 10 2 4 1 10 10 1 1 1 ...
  ..$ clump thickness      : int [1:683] 5 5 3 6 4 8 1 2 2 4 ...
  ..$ uniformity cell size : int [1:683] 1 4 1 8 1 10 1 1 1 2 ...
  ..$ uniformity cell shape: int [1:683] 1 4 1 8 1 10 1 2 1 1 ...
  ..$ marginal adhesion    : int [1:683] 1 5 1 1 3 8 1 1 1 1 ...
  ..$ bland chromatin      : int [1:683] 3 3 3 3 3 9 3 3 1 2 ...

Solution

  • Use list2env:

    list2env(new_dfs, .GlobalEnv)