Sample two realisations from a normally distributed population

    alpha <- 0.5             # 50% confidence

    n <- 2                   # sample size
    mu <- 0                  # population mean
    sigma <- 1               # population standard deviation
    
    x <- rnorm(n, mu, sigma) # generate the sample
    
    sort(x)
[1] 1.379743 1.476975

Calculate the confidence interval

    error <- qt(1-alpha/2, df=n-1)*sd(x)/sqrt(n)
    mean(x) + c(-1, +1) * error
[1] 1.379743 1.476975

Calculate again using one sample t-test function

    t.test(x, conf.level = alpha)

    One Sample t-test

data:  x
t = 29.38, df = 1, p-value = 0.02166
alternative hypothesis: true mean is not equal to 0
50 percent confidence interval:
 1.379743 1.476975
sample estimates:
mean of x 
 1.428359 

Computing Environment

R version 3.2.2 (2015-08-14)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 8 x64 (build 9200)

locale:
[1] LC_COLLATE=English_United Kingdom.1252  LC_CTYPE=English_United Kingdom.1252   
[3] LC_MONETARY=English_United Kingdom.1252 LC_NUMERIC=C                           
[5] LC_TIME=English_United Kingdom.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] knitr_1.12.3

loaded via a namespace (and not attached):
 [1] magrittr_1.5    formatR_1.3     tools_3.2.2     htmltools_0.3.5 yaml_2.1.13     Rcpp_0.12.4     stringi_1.0-1  
 [8] rmarkdown_0.9.6 stringr_1.0.0   digest_0.6.9    evaluate_0.9   
[1] "~/X/"

This took 0.28 seconds to execute.