title: How to create a new column based on other columns in a data.table?
body: <pre><code>DT0 = data.table(x=rep(c(NA,NA,NA)), y=c(0,1,NA), v=c(0, 0, NA), l=c(1,1,1))
  DT0
  #    x  y  v l
  #1: NA  0  0 1
  #2: NA  1  0 1
  #3: NA NA NA 1
  </code></pre>
  
  <p>Based on the first three cols <code>x</code>, <code>y</code> and <code>v</code> I want to add a new col with following output</p>
  
  <pre><code>#1:  No
  #2: Yes
  #3:  NA
  </code></pre>
  
  <p><code>NA</code> if all rows are <code>NA</code>. <code>Yes</code> if any of them is <code>1</code> else <code>0</code>. My current approach is </p>
  
  <pre><code>relevant_cols &lt;- c('x', 'y', 'v')
  new &lt;- data.table(apply(DT0[, relevant_cols, with=F], 1, function(val) { ifelse(all(is.na(val)), NA_character_, ifelse(any(val == TRUE, na.rm = TRUE), 'Yes', 'No')) }))
  DT0[, new:= new]
  DT0
  #    x  y  v l new
  #1: NA  0  0 1  No
  #2: NA  1  0 1 Yes
  #3: NA NA NA 1  NA
  </code></pre>
  
  <p>However, as the actual <code>data.table</code> is large, is there a better way to do this?</p>
  
  <p><strong>Edit:</strong>
  Often the data.table entries are non-numeric hence it would be quite helpful if I can have a more general solution than using <code>pmax</code> <code>e.g.</code>,  </p>
  
  <pre><code>DT = data.table(x=rep(c(NA,NA,NA)), y=c('No','Yes',NA), v=c('No', 'No', NA), l=c(1,1,1))
  DT
  #    x  y     v l
  #1: NA  No   No 1
  #2: NA  Yes  No 1
  #3: NA NA    NA 1
  </code></pre>