title: Custom na.action in R
body: <p>I'm currently trying to build an LDA model on a dataset which contains some missing (<code>NA</code>) values. I want to, for example, impute the mean for <code>NA</code> values. From what I understand, I can set <code>na.action=na.omit</code> in the <code>lda</code> and <code>predict</code> functions which will remove the observations when building the model, and force return of <code>NA</code> when making predictions.</p>
  
  <pre><code>my.dat &lt;- as.data.frame(cbind(
      c(0, 1, 0, 1, 1, 0),
      c(5, 8, 9, 1, -1, NA),
      c(-2.4, -4.0, -4.4, -0.5, 0.7, -0.3)
  ))
  mod &lt;- lda(my.dat[,-1], my.dat[,1], na.action=na.omit)
  predict(mod, my.dat[,-1], na.action=na.omit)
  </code></pre>
  
  <p>But I want now to impute the means where I have an <code>NA</code> value. So, I can define my own <code>na.impute</code> function. But, I cannot understand what is passed to this function, and what I need to return.</p>
  
  <pre><code>na.impute &lt;- function (object) {
      print(object)
      object
  }
  </code></pre>
  
  <p>which gives me output:</p>
  
  <pre><code>[1] g x
  &lt;0 rows&gt; (or 0-length row.names)
  </code></pre>
  
  <p>which doesn't make much sense to me. I cannot find any guidance in the documentation. What exactly is <code>object</code>, and how am I supposed to manipulate it to overwrite NA values?</p>