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

John Kane jrkrideau at yahoo.ca
Wed Feb 6 15:21:58 CET 2008


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
> interval etc, instead of
> 
> 
> [[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