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

From: Daniel Stahl <daniel_stahl_at_operamail.com>
Date: Sun, 06 Jul 2008 06:14:02 +0800


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

Cheers, Daniel

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
--
_______________________________________________










-- 

______________________________________________
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 Sat 05 Jul 2008 - 22:19:44 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 Sat 05 Jul 2008 - 22:31:24 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.

list of date sections of archive