Skip to content
Back to formatted view

Raw Message

Message-ID: <E8D3DF4E-67FC-4B94-8AF4-E38CDDC6BAE0@comcast.net>
Date: 2012-02-23T18:55:12Z
From: David Winsemius
Subject: Aggregate with Function List ?
In-Reply-To: <AF64F454BE6C2649B351CCEBD23ADDE7058D26EA@EXCHCLUSTER.SYNTA.COM>

On Feb 23, 2012, at 1:41 PM, Michael Karol wrote:

> R Experts
>
>
>
>  I wish to tabulate into one data frame statistics summarizing
> concentration data.   The summary is to include mean, standard
> deviation, median, min and max.  I wish to have summaries by Dose, Day
> and Time.   I can do this by calling aggregate once for each of the
> statistics (mean, standard deviation, median, min and max) and then
> execute 4 merges to merging the 5 data frames into one.  (Example
> aggregate code for mean only is shown below.)
>
>  Can someone show me the coding to do this as one command, rather than
> 5 calls to aggregate and 4 merges.  In other words, in essence, I'd  
> like
> to present to "FUN =" a list of functions, so all the summary stats  
> come
> back in one data frame.  Your assistance is appreciated.  Thank you.
>
Perhaps something like this?

MeansByDoseDayTime <- aggregate(as.double(DF$Concentration), by =
list(DF$Dose, DF$Day, DF$Time), FUN =
       function(x) c( mean(x, trim = 0, na.rm = T, weights=NULL),
                      sd(x, na.rm=TRUE),
                      median(x, na.rm=TRUE),
                      min(na.rm=TRUE),
                      max(x, na.rm=TRUE)
                    )
         )
>
>
>

David Winsemius, MD
West Hartford, CT