title: Extra columns appearing while running loop in R
body: <p>I have a data frame as following:</p>
  
  <pre><code>     word count    word  tf score word probability log values TFxIDF score
  1   yemen   380   yemen 1.0000000       0.05393896   2.919902     2.919902
  2 strikes   116 strikes 0.3052632       0.01646558   4.106483     1.253558
  </code></pre>
  
  <p>But when I run the following code:</p>
  
  <pre><code>p1 &lt;- read.csv("F:/M.Tech/Semester4/Thesis/Code/a1.csv")
  x &lt;- nrow(p1)
  q &lt;- p1[1,2]
  
  for(i in 1:x) {
    p1[i,4]=p1[i,2]/q
  }
  
  for(i in 1:x) {
    p1[i,5]=p1[i,2]/p
  }
  
  for(i in 1:x) {
    p1[i,6]= -log(p1[i,5])
  }
  
  for(i in 1:x) {
    p1[i,7]= p1[i,4]*p1[i,6]
  }
  </code></pre>
  
  <p>I get the other data frame with extra columns as:</p>
  
  <pre><code>   NA    word count    word  tf score word probability log values TFxIDF score Keyword Probability
  1   1   yemen   380   yemen 1.0000000       0.05393896   2.919902     2.919902                  NA
  2   2 strikes   116 strikes 0.3052632       0.01646558   4.106483     1.253558                 0.5
  </code></pre>
  
  <p>How can I remove these extra columns from coming?</p>