title: r - split one csv file into multiple txt files
body: <p>I need to split one large .csv file, with about 9 columns and more than 9,000 rows, into a separate .txt file for each row, and name each newly generated file by the name in its first column.</p>
  
  <p>e.g.
  for the .csv file:</p>
  
  <pre><code>01001_r1    32.4327 -86.6190    0.65    0.20    0.15    1.33    5.47    8
  01001_r2    32.4327 -86.6190    0.65    0.20    0.15    1.33    5.46    8
  01001_r3    32.4327 -86.6190    0.80    0.15    0.05    1.33    5.23    10
  01003_r1    30.4887 -87.6918    0.65    0.20    0.15    1.33    5.23    9
  01003_r2    30.4887 -87.6918    0.80    0.15    0.05    1.33    5.25    9
  01003_r3    30.4887 -87.6918    0.65    0.20    0.15    1.33    4.96    8
  </code></pre>
  
  <p>I would end up with 6 files, with one row each.</p>
  
  <p>Columns in the output file need to be 'tab separated', and the file must not contain neither row or column names.</p>
  
  <p>e.g the output files should look like this:</p>
  
  <pre><code>01001_r1    32.4327 -86.6190    0.65    0.20    0.15    1.33    5.47    8
  </code></pre>
  
  <p>This is where I've gotten this far: </p>
  
  <pre><code>#set 'working directory'
  setwd('C:/Users/Data/soils_data/sitesoil_in')
  
  #identify data frame from .csv file
  sd &lt;- read.csv('site_soil.csv', sep="\t", header=F, fill=F)
  
  lapply(1:nrow(sd), function(i) write.csv(sd[i,],
                                           file = paste0(sd[i,1], ".txt"),
                                           row.names = F, header = F,
                                           quote = F))
  </code></pre>
  
  <p>And this is what I get for each output file:</p>
  
  <p>file name: 01001_r1</p>
  
  <pre><code>V1,V2,V3,V4,V5,V6,V7,V8,V9
  01001_r1,32.4327,-86.619,0.65,0.2,0.15,1.33,5.47,8
  </code></pre>
  
  <p>I can't get it to eliminate the columns names or to separate the columns with tabs.
  I have tried with header = F, or col.names = F to eliminate headings, and sep = "\t" to separate the columns but it does not recognize the commands.</p>
  
  <p>I would appreciate any help.
  Thanks,
  E.</p>
  
  <p>Following all suggestions, this is the simpler code that would do the trick:</p>
  
  <pre><code>#set 'working directory'
  setwd('C:/Users/Elena/Desktop/DayCent_muvp_MODEL/DayCent_SourceData/soils_data/sitesoil_in')
  
  #identify data frame from .csv file
  sd &lt;- read.csv('site_soil.csv', sep="\t", header=F, fill=F)
  
  lapply(1:nrow(sd), 
         function(i) write.table(sd[i,],
                                 file = paste0(sd[i,1], ".txt",collapse = ""),
                                 row.names = FALSE, col.names = FALSE,
                                 sep = "\t"
         ))
  </code></pre>
  
  <p>Thank you all for your help.
  E.</p>