[S] SUMMARY: Beginner Question on apply() & tapply()

Marc Feldesman (feldesmanm@pdx.edu)
Mon, 01 Jun 1998 14:39:28 -0700


Thanks to all who quickly responded to my question regarding the use of
apply() & tapply(). I won't repeat the problem, but several different, but
equally effective solutions emerged, none involving apply() or tapply()
directly.

The most direct solution came from Bill Dunlap of Mathsoft and also Bert
Gunter. In short, this solution (with slight modifications) looks like this:

vcv<-by(headdata[,2:5], headdata[,8], var). This can be "prettified" by
using list(headdata[,8]) instead of headdata[,8].

Brian Ripley offered two solutions:

vcv<-lapply(split(headdata[,2:5], headdata[,8]), var)

and also a loop version of the same:

for (i in unique(headdata[,2:5]))
print(var(headdata[headdata[,8]==i,2:5]))

Thanks also to Jim Robison-Cox and Samuel Buttrey for other solutions.

Dr. Marc R. Feldesman
Professor and Chairman
Anthropology Department
Portland State University
P.O. Box 751
Portland, Oregon 97207
email: feldesmanm@pdx.edu
phone: 503-725-3081
fax: 503-725-3905
-----------------------------------------------------------------------
This message was distributed by s-news@wubios.wustl.edu. To unsubscribe
send e-mail to s-news-request@wubios.wustl.edu with the BODY of the
message: unsubscribe s-news