title: ifelse data.table multiplication while keeping NA values as real
body: <p>I have tried both solutions from
  <a href="https://stackoverflow.com/questions/20535505/replacing-all-missing-values-in-r-data-table-with-a-valu">Replacing all missing values in R data.table with a value</a>, but I am not able to find <strong>tmpd</strong>. </p>
  
  <pre><code>library(data.table)
  set.seed(10)
  datatmps &lt;- data.table(ID = seq(11), A = c(0.32, sample(1:40, 10,)), B = c(NA, 4.3, 
  32.21, -0.9832, NA, 45, 3, 2, 90, 109.3, NA), C = c(sample(1:30, 10,), -0.87))
  setkey(datatmps, ID)
  for (i in seq_along(datatmps)) set(datatmps, i=which(is.na(datatmps[[i]])), j=i, 
  value=NA_real_)
  tmpd &lt;- datatmps[, lapply(.SD, function(x) {
  ifelse(x &lt; 62.276, 6.107799961 + x * (0.4436518521 + x * (0.01428945805 + x * 
  (0.0002650648471 + x * (0.000003031240396 + x * (0.00000002034080948 + x *  
  0.00000000006136820929))))), 
  -296.901212123675 + 16.9015967001546 * x - 0.302242100380422 * x^2 + 
  0.00264123776535373 * x^3)}), by = key(datatmps)]
  
  # Error in `[.data.table`(datatmps, , lapply(.SD, function(x) { : 
  # Column 2 of result for group 2 is type 'double' but expecting type 'logical'. 
  # Column types must be consistent for each group.
  </code></pre>
  
  <p>What changes need to be made to the code to get it to work?</p>
  
  <p>Thank you.</p>