title: R- Replace all values in rows of dataframe after first NA by NA
body: <p>I have a dataframe of 3500 observations and 278 variables. For each row going from the first column, I want to replace all values occurring after the first NA by NAs. For instance, I want to go from a dataframe like so:</p>
  
  <pre><code>X1 X2 X3 X4 X5
   1  3 NA  6  9
   1 NA  4  6 18
   6  7 NA  3  1 
  10  1  2 NA  2 
  </code></pre>
  
  <p>To something like</p>
  
  <pre><code>X1 X2 X3 X4 X5
   1  3 NA NA NA
   1 NA NA NA NA
   6  7 NA NA NA 
  10  1  2 NA NA   
  </code></pre>
  
  <p>I tried using the following nested for loop, but it  is not terminating:</p>
  
  <pre><code>for(i in 2:3500){
   firstna &lt;- min(which(is.na(df[i,])))
   df[i, firstna:278] &lt;- NA
  }
  </code></pre>
  
  <p>Is there a more efficient way to do this? Thanks in advance.</p>