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

From: John Kane <jrkrideau_at_yahoo.ca>
Date: Wed, 6 Feb 2008 09:21:58 -0500 (EST)

There may be an easier way but you can extract the desired values from the list values in t str(t) to see the elements in t.

test <- matrix(c(1, 1,2,2), 2,2)
tt <- apply(test, 1, t.test)

ttable <- function(tlist) {
tframe <- data.frame(NULL)
for(i in 1:length(tlist)){
t.value <- tlist[[i]][1]
dfs <- tlist[[i]][2]
conf.int1 <- tlist[[i]]\$conf.int[1]
conf.int2 <- tlist[[i]]\$conf.int[2]
p.value <- tlist[[i]][3]
t.vect <- cbind(t.value, dfs, conf.int1, conf.int2, p.value)
tframe <- rbind(tframe, t.vect)
}
}

myts <- ttable(tt) ; myts

• Ng Stanley <stanleyngkl_at_gmail.com> 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
>
>
> [[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
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained,
> reproducible code.
>

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. Received on Wed 06 Feb 2008 - 14:25:43 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Wed 06 Feb 2008 - 15:30:12 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.