title: R for loop only completing first iteration
body: <p>I'm trying to split a csv file by column Customer.Code and write the resulting Dataframes to seperate csv files.</p>
  
  <pre><code>splittit&lt;- function(file){
  
  data&lt;-read.csv(file)
  
  data&lt;-split(data,data$Client.Code)
  
  x&lt;- length(data)
  
  for(i in x){
    custdata&lt;- data[i] 
    custdata&lt;- as.data.frame(custdata)
    customer&lt;- custdata[1,18]
    customer&lt;- as.vector(customer)
    filename&lt;- paste(as.character(customer),".csv")
    write.csv(custdata, file= filename)
  }
  }
  </code></pre>
  
  <p>If anyone can help me as to why only the first csv file is being written i would be very grateful.</p>
  
  <p>Thanks
  in advance</p>