title: Replace values with NA where date is greater then... with R
body: <p>I tried to create exact sample data but failed, here is attempt:</p>
  
  <pre><code>data1 &lt;- data.frame(date=as.Date(as.character(c("01-03-2015","01-04-2015","01-05-2015")),"%d-%m-%Y"), Val=rnorm(3,1,1))
  data2 &lt;- data.frame(date=c(NA,"",NA), Val=rnorm(3,1,1))
  data3 &lt;- data.frame(date=as.Date(as.character(c("01-09-2015","01-10-2015","01-11-2015")),"%d-%m-%Y"), Val=rnorm(3,1,1))
  
  do.call(cbind, list(data1,data2,data3))
  </code></pre>
  
  <p>The sample data should look like this (I tried to bind with <code>rbind</code> but it fails to me for unknown reason). </p>
  
  <pre><code>        date        Val 
  1 2015-03-01 -0.8496063 
  2 2015-04-01  1.5014609    
  3 2015-05-01  0.7923492 
  4        &lt;NA&gt; 1.6646475
  5             1.1976965   # empty string in column date
  6        &lt;NA&gt; 0.9105403   # NA in column date 
  7 2015-09-01  0.6214811
  8 2015-10-01  1.1314259
  </code></pre>
  
  <p>What I would like to do is to replace all values of column Val with <code>NA</code>, where in column date, dates are greater then <code>2015-09-01</code> </p>
  
  <p>Here is not exactly the sample data I have (It matters whether empty string or NA, these properties must stay intact).</p>
  
  <pre><code>Sampdata &lt;- data.frame(date=c(as.Date(as.character(c("01-03-2015","01-04-2015","01-05-2015")),"%d-%m-%Y"),"NA","NA","NA",
                            as.Date(as.character(c("01-08-2015","01-09-2015")),"%d-%m-%Y")), Val=rnorm(8,1,1))
  
  
  Sampdata$Val &lt;- ifelse(Sampdata$date&gt;=(as.Date(as.character("2015-09-01"))),NA,Sampdata$Val)
  </code></pre>
  
  <p>The above solution fails, since it replaces with NA also those rows where the column date contains NA and empty string. </p>
  
  <p>Desired solution:</p>
  
  <pre><code>            date        Val 
  1 2015-03-01 -0.8496063 
  2 2015-04-01  1.5014609    
  3 2015-05-01  0.7923492 
  4        &lt;NA&gt; 1.6646475
  5             1.1976965  
  6        &lt;NA&gt; 0.9105403  
  7 2015-09-01  NA
  8 2015-10-01  NA
  </code></pre>
  
  <p><strong>EDIT:</strong> </p>
  
  <p>So let's correct the sample date to this: (no empty string)</p>
  
  <pre><code>Sampdata &lt;- data.frame(date=c(as.Date(as.character(c("01-03-2015","01-04-2015","01-05-2015")),"%d-%m-%Y"),"NA","NA","NA",
                            as.Date(as.character(c("01-08-2015","01-09-2015")),"%d-%m-%Y")),   Val=rnorm(8,1,1))
  </code></pre>
  
  <p>The proposed solution:</p>
  
  <pre><code>indx &lt;- as.Date(Sampdata$date) &gt;= '2015-09-01'
  Sampdata$Val[indx &amp; !is.na(indx)] &lt;- NA
  Sampdata
  </code></pre>
  
  <p>Gives on my pc this:</p>
  
  <pre><code>        date        Val
  1 2015-03-01  1.4437853
  2 2015-04-01 -0.1695267
  3 2015-05-01  0.5083815
  4       &lt;NA&gt;         NA
  5       &lt;NA&gt;         NA
  6       &lt;NA&gt;         NA
  7 2015-08-01  0.3026487
  8 2015-09-01         NA
  </code></pre>