title: Generating multiple confidence intervals from samples of a normal distribution in R
body: <p>I am an statistics student and R beginner (understatement of the year) trying to generate multiple confidence intervals for randomly generated samples of a normal distribution as part of an assignment.</p>
  
  <p>I used the function</p>
  
  <pre><code>data &lt;- replicate(25, rnorm(20, 50, 6))
  </code></pre>
  
  <p>to generate 25 samples of size n=20 from a N(50, 6^2) distribution (in a double matrix).</p>
  
  <p>My question is, how do I find a 95% confidence interval for each sample of this distribution? I know that I can use colMeans(data) and sd(data) to find the sample mean and sample standard deviation for each sample, but I am having a brain fart trying to think of a function that can generate the confidence intervals for all columns in the double matrix (data). </p>
  
  <p>As of now, my (extremely crude) solution consists of creating the functions</p>
  
  <pre><code>left &lt;- function (x,y){x-(qnorm(0.975)*y/sqrt(20))}
  right &lt;- function (x,y){x+(qnorm(0.975)*y/sqrt(20))}
  
  left(colMeans(data), sd(data)
  right(colMeans(data), sd(data)
  </code></pre>
  
  <p>to generate 2 vectors of left and right bounds. Please let me know if there is a better way I can do this.</p>