title: R: How do I create a new row, then add some cells from the previous row, iterating through the whole table like this?
body: <p>I'd like to take each cell from V9-13 here and create a new row below each existing row, adding the values from cells V9-13 to the new row. This means that row 1 will have values V1-V8, then the new row below it will have V9-V13 from row 1 in the V1-V5 columns of that row.</p>
  <p><a href="https://i.stack.imgur.com/389lR.png" rel="nofollow noreferrer">Here's an image of the sheet</a></p>
  <pre><code>{
  
  library(&quot;readxl&quot;)
  library(&quot;dplyr&quot;)
  
  text_data &lt;- read.delim(&quot;C:\\Users\\Kavin Kadam\\Desktop\\UBC\\PCIGR\\IoliteOutlier\\Individual Answers_472.txt&quot;, skip=19, header=FALSE)
  
  x&lt;-(nrow(text_data))
  
  for (i in 1:x) {
    text_data_refined&lt;-dplyr::add_row(
      text_data,
      V1 = text_data$V9[i-1],
      V2 = text_data$V10[i-1],
      V3 = text_data$V11[i-1],
      V4 = text_data$V12[i-1],
      V5 = text_data$V13[i-1],
      .after = text_data_refined[i,]
      )
    }
  
  }
  </code></pre>
  <p>The sample output would be as in this image - it takes the V9-V13 from the previous row and adds it to the new row here:</p>
  <p><a href="https://i.stack.imgur.com/kGqM0.png" rel="nofollow noreferrer">here</a></p>