s-news
[Top] [All Lists]

Re: How to create a "summary" data frame

To: <s-news@lists.biostat.wustl.edu>
Subject: Re: How to create a "summary" data frame
From: "Hunsicker, Lawrence" <lawrence-hunsicker@uiowa.edu>
Date: Thu, 25 Dec 2008 08:35:36 -0600
Thread-index: Aclmng002sVNyvwCRia3LO8Ypm2J5A==
Thread-topic: RE: [S] How to create a "summary" data frame

Good morning and Merry Christmas to all:

And thanks to Steve Su, Alan Hochberg, and Chris Barker for help with my question above.

Steves solution, using tapply, seems the most straight forward, though one can probably get to the same place using by.  The problem with by is that when its output is combined into a data frame, it is entered as a series of columns, not rows even when delisted as suggested by Alan.  tapply works nicely to give a column vector that works well with cbind.  I am pretty sure that one could use t(by(x)) but I didnt actually check that out.

One other caution.  One has to be sure that the names column is entered in cbind as an integer, not as character.  Else the other columns are coerced to character.  At least one program that works nicely is given below:

test <- tapply(working7$Scr.missing, working7$Center, function(x) sum(x==0)/length(x))

test1 <- tapply(working7$Scr.missing, working7$Center, function(x) length(x))

test2 <- data.frame(cbind(as.integer(names(test)), test, test1))

names(test2) <- c("Center", "PctScrMeas", "NumAtCtr")

Again, thanks to Steve, Alan, and Chris, and Merry Christmas to everyone.

Larry Hunsicker

<Prev in Thread] Current Thread [Next in Thread>