Is there a way to calculate, say, the mean, min and max using aggregate using one line of code? Or do I need to call them separately (e.g. aggregate(...,mean); aggregate(...,min)) and then merge the data back together? --j -- Jonathan A. Greenberg, PhD NRC Research Associate NASA Ames Research Center MS 242-4 Moffett Field, CA 94035-1000 Office: 650-604-5896 Cell: 415-794-5043 AIM: jgrn307 MSN: jgrn307 at hotmail.com
Try summaryBy in package doBy. e.g. using the built in dataset CO2: summaryBy(uptake ~ Plant, CO2, FUN = c(mean, min, max)) On 10/20/06, Jonathan Greenberg <jgreenberg at arc.nasa.gov> wrote:> Is there a way to calculate, say, the mean, min and max using aggregate > using one line of code? Or do I need to call them separately (e.g. > aggregate(...,mean); aggregate(...,min)) and then merge the data back > together? > > --j > > -- > Jonathan A. Greenberg, PhD > NRC Research Associate > NASA Ames Research Center > MS 242-4 > Moffett Field, CA 94035-1000 > Office: 650-604-5896 > Cell: 415-794-5043 > AIM: jgrn307 > MSN: jgrn307 at hotmail.com > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >
> Try summaryBy in package doBy. e.g. using the built in dataset CO2: > > summaryBy(uptake ~ Plant, CO2, FUN = c(mean, min, max))Or with reshape with a little more work: cm <- melt(CO2, id=1:4) cast(cm, Type ~ Treatment, c(min,mean,max)) but you get some extra flexibility: cast(cm, result_variable + Type ~ Treatment, c(min,mean,max)) cast(cm, Type ~ Treatment ~ result_variable, c(min,mean,max)) cast(cm, Type + Treatment ~ result_variable, c(min,mean,max)) Regards, Hadley
Try the summary function, which pretty much does exactly that. -Alex On 20 Oct 2006, at 23:44, Jonathan Greenberg wrote:> Is there a way to calculate, say, the mean, min and max using > aggregate > using one line of code? Or do I need to call them separately (e.g. > aggregate(...,mean); aggregate(...,min)) and then merge the data back > together? > > --j > > -- > Jonathan A. Greenberg, PhD > NRC Research Associate > NASA Ames Research Center > MS 242-4 > Moffett Field, CA 94035-1000 > Office: 650-604-5896 > Cell: 415-794-5043 > AIM: jgrn307 > MSN: jgrn307 at hotmail.com > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting- > guide.html > and provide commented, minimal, self-contained, reproducible code.