title: R Error (from NA's to 0): duplicate subscripts for column in Data Frame
body: <p>I looked at multiple answers on Stackoverflow, but I stil couldn't fix my problem. I made a function that works, but I added something and now it won't work anymore. I want to replace all NA's to 0, which seems simple to me. </p>
  
  <p>This is my function, and I added <code>bframe[is.na(bframe)] &lt;- 0</code>: </p>
  
  <pre><code>B &lt;- function(frame1, frame2, column){
    bframe &lt;- merge(frame 1, frame2, by = column, all = TRUE)
    bframe$result &lt;- bframe$freq.x - bframe$freq.y
    bframe$percentage &lt;- (bframe$result/bframe$freq.y)*100
    bframe[is.na(bframe)] &lt;- 0
    return(bframe)
  }
  
  B(DT2_1, 2_1, "BurgS")
  </code></pre>
  
  <p>However, it gives this error: <code>Error in '[&lt;-.data.frame'('* tmp *, thisvar, value = 0) : duplicate subscripts for columns</code>. </p>
  
  <p>The error occurs because there are NAs and it cannot perform the calculations: </p>
  
  <pre><code>BurgS  freq.x  freq.y  result   percentage  percentageABS
  1      9204    184042  -174838  -94.99897   94.99897 
  2      150     3034    -2884    -95.05603   95.05603 
  3      130     2602    -2472    -95.00384   95.00384 
  98     NA      47      NA       NA          NA 
  </code></pre>
  
  <p>Not every data frame has this structure, so I am looking for a solution that changes NA's in the <strong>whole</strong> data set. Can someone help me out?</p>
  
  <p>Changed 26/6/2018: I stumbled up the solution myself. The code is as follows, so that the <code>NA</code> of <code>freq.x</code> is changed to 0 and still can be part of the calculations which the outcome is shown in the last three columns:</p>
  
  <pre><code>B &lt;- function(frame1, frame2, column){
    bframe$freq.x[is.na(bframe$freq.x)] &lt;- 0
    bframe &lt;- merge(frame 1, frame2, by = column, all = TRUE)
    bframe$result &lt;- bframe$freq.x - bframe$freq.y
    bframe$percentage &lt;- (bframe$result/bframe$freq.y)*100
    return(bframe)
  }
  
  B(DT2_1, 2_1, "BurgS")
  </code></pre>