title: How to plot the density curve of a vector containing missing values in R?
body: <p>I have a data set with some NA values (missing values).</p>
  
  <p>Because I need to plot some density curves from this data, I've created the following function:</p>
  
  <pre><code>plotDistribution = function (x) {
      N = length(x)
      hist( x,col = "light blue",
            probability = TRUE)
      lines(density(x), col = "red", lwd = 3)
      rug(x)
  }
  </code></pre>
  
  <p>It works just fine if x has no missing values but because my data do contain missing values I'm getting the following message: <em>Error in density.default(x) : 'x' contains missing values</em>.</p>
  
  <p>My question is: how to plot the density curve of the non-missing values in a data set? How can I ignore the NA and plot the curve as if they don't exist?</p>