title: How do I calculate the probability for a given quantile in R?
body: <p>Using R, it is trivial to calculate the quantiles for given probabilities in a sampled distribution:</p>
  
  <pre><code>x &lt;- rnorm(1000, mean=4, sd=2)
  quantile(x, .9) # results in 6.705755
  </code></pre>
  
  <p>However, I can't find an easy way to do the inverse—calculate the probability for a given quantile in the sample <code>x</code>. The closest I've come is to use <code>pnorm()</code> with the same mean and standard deviation I used when creating the sample:</p>
  
  <pre><code>pnorm(5, mean=4, sd=2) # results in 0.6914625
  </code></pre>
  
  <p>However, because this is calculating the probability from the full normal distribution, and not the sample <code>x</code>, it's not entirely accurate.</p>
  
  <p>Is there a function that essentially does the inverse of  <code>quantile()</code>? Something that essentially lets me do the same thing as <code>pnorm()</code> but with a sample? Something like this:</p>
  
  <pre><code>backwards_quantile(x, 5)
  </code></pre>
  
  <p>I've found the <code>ecdf()</code> function, but can't figure out a way to make it result in a single probability instead of a full equation object.</p>