title: Write column values to file with matching value from second column in R
body: <p>I have a dataframe <code>df</code> in R that has several columns, of which <code>columnA</code> and <code>columnB</code> are of interest here:</p>
  
  <pre><code>columnA    columnB
  ab1        'This is a string'
  ts4        'This is another string'
  pq9        'This is yet another string'
  </code></pre>
  
  <p>I want to write the strings to a file and include the matching <code>columnA</code> value in the filename.</p>
  
  <pre><code>sapply(df$columnB, function(x){
    write.table(x,
            file = paste("matching_column_a_",
                         which(x == df$columnB, arr.ind = T),
                         ".txt",
                         sep = ""),
            col.names = FALSE,
            row.names = FALSE,
            append=F,
            sep = "\t",
            quote = FALSE)
  })
  </code></pre>
  
  <p>However, my try gives only an index of the rows but that is not of use for me.</p>
  
  <p>Is there a way to write it to a file where the matching filename of the file with the <code>columnB</code> string is something like <code>matching_column_a_ab1.txt</code>, <code>...a_ts4.txt</code>, etc?</p>