Let's say I have two samples and I want to calculate confidence intervals for the means of each sample.

x = rnorm(10)
y = rnorm(10)

Using the t.test command I'm able to get the following output.

> t.test(x, y)

    Welch Two Sample t-test

data:  x and y
t = -0.0104, df = 17.17, p-value = 0.9918
alternative hypothesis: true difference in means is not equal to 0
95 percent confidence interval:
 -1.077822  1.067245
sample estimates:
 mean of x  mean of y 
-0.2235438 -0.2182557 

However, what if I want the 95% confidence intervals for each sample. Is that a manual calculation I have to do. I want to generate confidence intervals for each sample so that I can compare the two in regards to whether I should reject the null hypothesis.

Basically, I want to mimic this in R.


1 Answer 1


Your question leave some considerable doubt about what, exactly, this in 'mimic this' consists of. You should be more explicit.

Do you want one sample confidence intervals for the means?

Then t.test can do it easily, by doing it one sample at a time.


You can even extract the confidence interval part of the output and if you want, assign it to a variable:


(Or do you want to know how to produce a particular display? That's easy enough, once the values are calculated.)


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.