title: Export each data frame within a list to csv
body: <p>I have a list of data frames. Each data frame has the same column names and a varying number of rows. I would like to export each data frame within my list to its own csv file. The file name should be the name of the data frame. I have looked through several forum posts to try to different suggestions, but many have either not worked or gave me a blank csv file. Most of the posts I viewed were ~4 years old so that may be part of it.</p>
  
  <p>This is the code I currently have:</p>
  
  <pre><code>    #Export each data frame within a list
      export = function(data){
      filename = function(x) paste(names(data[[x]]), ".csv");
      write.csv(data, filename,);
      }
  
      export(data)
  </code></pre>
  
  <p>The error I get is</p>
  
  <pre><code>"Error in data.frame(list(Column1 = c(1L, 2L, 3L, 4L, : 
  arguments imply differing number of rows: 62, 49, 41, 55, 39, 32, 34
  </code></pre>
  
  <p>Then I thought, well maybe I need to use <code>data[[x]]</code> in write.csv to read:</p>
  
  <pre><code>    write.csv(data[[x]], filename,)
  </code></pre>
  
  <p>But that gives me the error <code>"Error in is.data.frame(x): object 'x' not found"</code></p>
  
  <p>Here is the structure of my list of data frames.</p>
  
  <pre><code>    str(data)
      List of 10
       $ :'data.frame':   62 obs. of  6 variables:
        ..$ TQ: Factor w/ 396 levels "V0Q1",..: 167 168 97 192 2 98 193 194 99 3 ...
        ..$ CO               : int [1:62] 1 1 1 1 1 1 1 1 1 1 ...
        ..$ PhP          : int [1:62] 166576 565275 1091111 1181342 1735982 2237418 2354002 3869267 6155933 7027686 ...
        ..$ Position  : num [1:62] 0 0.456 2.419 2.63 3.792 ...
        ..$ D        : Factor w/ 2 levels "D2012",..: 1 1 1 2 1 1 2 2 1 1 ...
        ..$ bin_index         : int [1:62] 1 1 1 1 1 2 2 2 3 3 ...
       $ :'data.frame':   49 obs. of  6 variables:
        ..$ TQ: Factor w/ 396 levels "V03Q1",..: 227 169 228 229 230 231 232 233 234 235 ...
        ..$ CO               : int [1:49] 2 2 2 2 2 2 2 2 2 2 ...
        ..$ PhP           : int [1:49] 805189 2219895 3386011 3999185 4430767 4644792 5223962 5392366 6052813 6136478 ...
        ..$ Position  : num [1:49] 0.16 5.95 9.87 12.69 15.22 ...
        ..$ D        : Factor w/ 2 levels "D2012",..: 2 1 2 2 2 2 2 2 2 2 ...
        ..$ bin_index         : int [1:49] 1 2 2 3 4 4 4 4 5 5 ...
       $ :'data.frame':   41 obs. of  6 variables:
        ..$ TQ: Factor w/ 396 levels "V03Q",..: 28 257 258 105 144 29 106 30 145 259 ...
        ..$ CO               : int [1:41] 3 3 3 3 3 3 3 3 3 3 ...
        ..$ PhP          : int [1:41] 1055462 2022884 2222474 2269935 3497149 3755007 5079223 6855634 7091838 10284891 ...
        ..$ Position  : num [1:41] 1.3 4.94 7.52 8.34 11.28 ...
        ..$ D        : Factor w/ 2 levels "D2012",..: 1 2 2 1 1 1 1 1 1 2 ...
        ..$ bin_index         : int [1:41] 1 1 2 2 3 3 4 5 6 8 ...
  </code></pre>
  
  <p>Any suggestions? Thank you.</p>