[R] How to generate table output of t-test

Uwe Ligges ligges at statistik.tu-dortmund.de
Tue Feb 5 10:18:28 CET 2008



Ng Stanley wrote:
> Hi,
> 
> Given
> 
> test <- matrix(c(1, 1,2,2), 2,2)
> t <- apply(test, 1, t.test)
 >
> How can I obtain a table of p-values, confidence interval etc, instead of

A quick hack would be:

m <- t(sapply(t, function(x)  c(x[["p.value"]], x[["conf.int"]])))
colnames(m) <- c("p", "lwr", "upr")
m


> 
> [[1]]
> 
>         One Sample t-test
> 
> data:  newX[, i]
> t = 3, df = 1, p-value = 0.2048
> alternative hypothesis: true mean is not equal to 0
> 95 percent confidence interval:
>  -4.853102  7.853102
> sample estimates:
> mean of x
>       1.5
> 
> 
> [[2]]
> 
>         One Sample t-test
> 
> data:  newX[, i]
> t = 3, df = 1, p-value = 0.2048
> alternative hypothesis: true mean is not equal to 0
> 95 percent confidence interval:
>  -4.853102  7.853102
> sample estimates:
> mean of x
>       1.5
> 
> 	[[alternative HTML version deleted]]
> 
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.



More information about the R-help mailing list