title: Updating Variable using functions in data.table?
body: <p>This is a very quick question, I also asked a more complicated one in <a href="https://stackoverflow.com/questions/21140218/add-dummies-with-conditions-in-data-table/21141409?noredirect=1#comment31817772_21141409">this link</a></p>
  
  <p>In this link, Roland kindly gave a very elegant solution to my problems. But I want to figure out why my solution doesn't work.</p>
  
  <pre><code>DT &lt;- data.table(UID = paste0("UID",rep(1:5,each=2), 
    date = as.IDate("2012-01-01","2012-01-02","2012-01-03","2012-01-04","2012-01-05","2012-01-06","2012-02-01","2012-02-02","2012-02-03","2012-02-04"),
    value = c(1:10)))
  </code></pre>
  
  <p>This is the fake data set.</p>
  
  <p>Now I want to create a new variable called Val2 based on the following condition:</p>
  
  <p>** Whether the date of each row is no "2012-01-02","2012-02-02".</p>
  
  <p>To achieve this, I tried this</p>
  
  <pre><code>1.  f &lt;- function(x){ 
  test &lt;- ifelse(x %in% as.Date(c("2012-01-02","2012-02-02")) , TRUE, FALSE)
  return(test)
  }
  
  DT[,Val2:= f(date)] 
  </code></pre>
  
  <p>But all Val2 are true, which is obviously wrong. </p>
  
  <p>As Roland pointed in my previous problem, I tried another one.</p>
  
  <pre><code>DT[, Val2:= sapply(date, function(x) x %in% as.Date(c("2012-01-02","2012-02-02")))]
  </code></pre>
  
  <p>Still not working with the following error:</p>
  
  <p><strong>Error in as.Date.default(x, ...) : 
    do not know how to convert 'x' to class ate?</strong></p>
  
  <p>Also I tried to modified based on the error hints, but all failed.</p>
  
  <p>Could you offer some suggestions? Thanks!</p>