s-news
[Top] [All Lists]

Question about aggregate() and statistics with greater than one v alue r

To: s-news@lists.biostat.wustl.edu
Subject: Question about aggregate() and statistics with greater than one v alue returned
From: "Li, Mike" <LiMIK@cder.fda.gov>
Date: Fri, 21 May 2004 13:15:46 -0400

Can you suggest a way to implement the aggregate function which allows it to return more than a single value for each subset of the data?

i.e. Suppose you have the following dataset:
dat _ data.frame(ID=c(rep(1,4),rep(2,4),rep(3,4)), TIME=rep(c(0,0,1,1), 3))

The aggregate function accepts arguments to "fun" that return single statistics, such as mean.
e.g. The following code is successful:
aggregate(dat$TIME, list(dat$ID),mean)

However, I want to have the aggregate function perform functions on the subsetted data that return several values, such as by using the "unique" function.

i.e. The following code fails:
aggregate(dat$TIME, list(dat$ID),unique)

Can you suggest an efficient way to perform operations on subsets of data?
Thanks much,
Mike Li

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