title: How do I index and save the strings in adjacent rows in a df in R?
body: <p>I have limited r knowledge and would like to run such a task in a big data frame:
  Data frame consists of binary answers of 1 and 2, and on the adjacent row the reasoning why the person chose that answer:</p>
  <div class="s-table-container">
  <table class="s-table">
  <thead>
  <tr>
  <th>A_answer1</th>
  <th>reasoning1</th>
  <th>B_answer2</th>
  <th>reasoning2</th>
  <th>A_answer3</th>
  <th>reasoning3</th>
  </tr>
  </thead>
  <tbody>
  <tr>
  <td>1</td>
  <td>&quot;some statement&quot;</td>
  <td>2</td>
  <td>&quot;some reasoning&quot;</td>
  <td>1</td>
  <td>&quot;yes&quot;</td>
  </tr>
  <tr>
  <td>2</td>
  <td>&quot;another statement&quot;</td>
  <td>1</td>
  <td>&quot;some sentence&quot;</td>
  <td>1</td>
  <td>&quot;because of x&quot;</td>
  </tr>
  </tbody>
  </table>
  </div>
  <p>As the first task I want to have 2 df of strings, if the answer is one, saving the adjacent string to a df. if the answer is 2, saving the string to another df. In the end I want to have a df1:</p>
  <p>&quot;some statement&quot;
  &quot;yes&quot;
  &quot;some sentence&quot;
  &quot;because of x&quot;</p>
  <p>and df2:</p>
  <p>&quot;some reasoning&quot;
  &quot;another statement&quot;</p>
  <p>I managed to do the first one with this loop:</p>
  <pre><code>drive &lt;- list() #create an empty list
  yield &lt;- list()
  c &lt;- 0
  
  for(i in seq(3,ncol(df),2)) {
    c&lt;- c+1
    temp &lt;- df[i+1]
    drive[[c]] &lt;- temp[df[i]==1]
    yield[[c]] &lt;- temp[df[i]==2]
  }
  
  
  lapply(drive, function(x) write.table( data.frame(x), 'drive.csv'  , append= T, sep=',' ))
  lapply(yield, function(x) write.table( data.frame(x), 'yield.csv'  , append= T, sep=',' ))
  </code></pre>
  <p>As the second task I would like to have 2 df of strings per condition. Answer 1 and answer 3 belong to the same condition &quot;A&quot;. I would like to extract strings from condition A per answer group 1 and 2.
  so in this case what I want is
  df1_A:
  &quot;same statement&quot;
  &quot;yes&quot;
  &quot;because of x&quot;</p>
  <p>and df2_A:
  &quot;another statement&quot;</p>
  <p>I appreciate your help!</p>