[S] tapply: problem, solution, question - summary

Matthew Wiener (mcw@ln.nimh.nih.gov)
Thu, 30 Apr 98 07:13:24 -0000


The basic answer to my earlier question about why tapply won't take a
matrix as its first argument is that that's the way it's written.
However, several people did suggest a nice workaround: use a tapply on a
vector of indices, and rewrite the function to take indices.

Here is the code from Bill Dunlap's reply, which is very similar to what
several others suggested.

tapply(1:nrow(mat), x$stimulus,
FUN=function(i, mat)cor(mat[i,1],mat[i,2]), mat=mat)

Thanks to those who answered, including Nick Ellis, Bill Venables, John
Wallace, Bert Gunter, and Bill Dunlap of Mathsoft. (I may have
inadvertently deleted a reply from one other person; sorry.)

Matt Wiener
NIMH
-----------------------------------------------------------------------
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