title: NA replacement using mean or median value? which will be better for my data?
body: <p>I have the following dataset:</p>
  
  <pre><code>5   3   3   5   10  10  3   8   2   12  8   6   2   5   6   5   10  4   3   5   4   3   3   5   8   3   5   6   6   1   10  3   6   6   5   8   3   4   3   4   4   3   2.5 1   4   2   2   3   5   10  4   4   6   3   2   3   8   3   4   4   3   3   4   8   4   4   2   4   4   3   2   10  6   3   7   3   5   3   1   4   3   4   3   4   4   2   3   2   4   7   4   6   3.5 3.5 5   3   4   3   5   3   1.5 2.5 3   7   2   5   3   4   2   4   5   3   4   5   4.5 4   6   3   2   1   3   2   2   3   4   6   2   4   2   3   6   1.5 3   3   1   4   3   3   2   3   2   2   6   3   15  1   4   5   2   6   2   4   8   2   8   4   4   4   3   8   4   4   8.5 3   2   7   0.5 3   3   3   2   3   2   4   5   6   2   3.5 3   3   2   2   2.5 2   2   5   2   8   2   4   3   3   2   7   2   4   2   4   4   3   2.5 3   3   3   5 NA NA NA NA NA  NA NA NA NA NA NA NA NA NA NA
  </code></pre>
  
  <p>I want to replace NA's using either <strong>Mean or Median value imputation method</strong>.</p>
  
  <p>Which method would be appropriate in such a case, and why?</p>
  
  <p>Please help me learning.</p>
  
  <p>Thanks.</p>
  
  <p>In R I am trying the same with Median using:</p>
  
  <pre><code># replacing with Median
  df$val[is.na(df$val)] &lt;- with(df, 
                                    ave(val, FUN = function(x) 
                                              median(x, na.rm = TRUE)) [is.na(df$val)]
  </code></pre>
  
  <p><strong>I have a feeling that this is not correct way of imputation.</strong></p>
  
  <p>Can someone help in clarifying my doubts:</p>
  
  <ol>
  <li>Will there be any effects on median imputation, given that there are some values with high frequencies and others with low freq.</li>
  <li>Because of outliers, imputation with "mean" would not be a good idea. So what alternative methods could be there?</li>
  </ol>
  
  <p>Thanks. </p>