[R] Problem solved: extracting values from a "by" function

Daniel Stahl daniel_stahl at operamail.com
Sun Jul 6 00:14:02 CEST 2008


Hi
I just discovered the answer thanks to a previous thread from Peter Daalgart
The command is: 
sapply(test, "[[", "statistic")

Cheers, Daniel

----- Original Message -----


To: r-help at r-project.org
Subject: extracting values from a "by" function
Date: Sun, 6 Jul 2008 05:59:04 +0800


Hello,

I am trying to extract t and pvalues from a 1000 ttests using the 
by-function but everythinhg I tried did not work. Unfortunately 
googling "by" is not very helpful. Any help will be very 
appreciated.
Cheers,
Danile Stall

*creating a data set
library(MASS)
dataset <- mvrnorm(160, mu, Sigma)
dataset <- as.data.frame(dataset)
dataset$GROUP <- rep(1:10, each=16)
data.uni <- reshape(df, varying = list(c("V1","V2")), 
v.names="Y",direction="long")
*the actual tests:
test<-by(data.uni, data.uni$GROUP, function(x)t.test(Y ~ time, data 
= x, paired = TRUE))
*in case this will help you:
summary(test)
str(test)

> summary(test)
    Length Class Mode
1  9      htest list
2  9      htest list
3  9      htest list
4  9      htest list
5  9      htest list
6  9      htest list
7  9      htest list
8  9      htest list
9  9      htest list
10 9      htest list
> str(test)

List of 10
  $ 1 :List of 9
   ..$ statistic  : Named num -4.26
   .. ..- attr(*, "names")= chr "t"
   ..$ parameter  : Named num 15
   .. ..- attr(*, "names")= chr "df"
   ..$ p.value    : num 0.000682
   ..$ conf.int   : atomic [1:2] -3.13 -1.04
   .. ..- attr(*, "conf.level")= num 0.95
   ..$ estimate   : Named num -2.09
   .. ..- attr(*, "names")= chr "mean of the differences"
   ..$ null.value : Named num 0
   .. ..- attr(*, "names")= chr "difference in means"
   ..$ alternative: chr "two.sided"
   ..$ method     : chr "Paired t-test"
   ..$ data.name  : chr "Y by time"
   ..- attr(*, "class")= chr "htest"
  $ 2 :List of 9



--
_______________________________________________










-- 



More information about the R-help mailing list