s-news
[Top] [All Lists]

Working with descriptive statistics

To: s-news@lists.biostat.wustl.edu
Subject: Working with descriptive statistics
From: matthew.austin@quintiles.com
Date: Fri, 17 Nov 2000 07:51:22 -0600
When I calculate descriptive statistics using tapply() on a dataframe I get
the results in the following form.

> t2.data
            A          B
1 -0.09757641 -0.2794609
2  0.28397480 -0.1517181
3 -0.32732973  0.1674076
4  0.06026633 -0.4264220

What I would like to produce is something in this form.

> temp.data
    response treatment visit
 -0.09757641         A     1
  0.28397480         A     2
 -0.32732973         A     3
  0.06026633         A     4
 -0.27946094         B     1
 -0.15171808         B     2
  0.16740755         B     3
 -0.42642198         B     4

The following code will convert from the 2-D array to the dataframe I want,
but I know there must be a better way.  Is there a function for this?

response <- rnorm(200)
treatment <- rep(c("A","B"),100)
visit <- rep(1:4,each=50)
t1.data <- data.frame(response, treatment, visit)
rm(response, treatment, visit)

t2.data <- tapply(t1.data$response, list(t1.data$visit, t1.data$treatment),
   mean)

t3.data <- data.frame(t2.data)
t4.data <- menuStackColumns(source = t3.data,
                    source.col.spec = list("<ALL>"),
                    group.col.p = F,
                    show.p= F)
t5.data <- cbind(t4.data, rep(attributes(t2.data)$dimnames[[2]], each=4) )
temp.data <- cbind(t5.data, rep(attributes(t2.data)$dimnames[[1]], 2) )

names(temp.data) <- c("response", "treatment", "visit")

t2.data
temp.data


Thanks for your help,

Matthew D. Austin
Biostatistician

Quintiles, Inc.
P. O. Box 9708
Kansas City, MO 64134
Phone:  (816) 767 3771  Fax:  (816) 767 7372
email:  matthew.austin@quintiles.com


<Prev in Thread] Current Thread [Next in Thread>
  • Working with descriptive statistics, matthew . austin <=