[R] Aggregate Help

Hall, Ken (CDC/OSELS/NCPHI) kha6 at CDC.GOV
Fri Aug 20 16:45:25 CEST 2010


Both of these worked great. Thanks for the quick response.

Question: which of the three codes (these two and Phil's) would be preferred from a "performance in R" perspective? They all ran extremely fast.

Ken 

-----Original Message-----
From: Gabor Grothendieck [mailto:ggrothendieck at gmail.com] 
Sent: Thursday, August 19, 2010 5:13 PM
To: Hall, Ken (CDC/OSELS/NCPHI)
Cc: r-help at r-project.org
Subject: Re: [R] Aggregate Help

On Thu, Aug 19, 2010 at 4:45 PM, Hall, Ken (CDC/OSELS/NCPHI)
<kha6 at cdc.gov> wrote:
> Please let me know if this is or is not the right place to ask these
> types of questions.
>
> Warning: I am new to R by two days.
>
> I have a simple dataset.
> I have loaded the dataset successfully using the following code:
>
> Filepath=(C:\temp\\pilot\dataset1.txt")
> Pilot=read.table(filepath, header=TRUE)
>
> Dataset1.txt is delimited and looks like this:
>
> Date    illness count
> 2006/01/01      derm    17
> 2006/01/01      derm    35
> 2006/01/02      derm    24
> 2006/01/02      derm    80
> .
> .
> .
> Total records like this approximately 18,000
>
> I would like to use the aggregate function to sum the count by similar
> date and illness, so it should look like this after the aggregate
>
> 2006/01/01      derm    52
> 2006/01/02      derm    104
> .

Try:

aggregate(Pilot[3], Pilot[1:2], sum)

or

aggregate(count ~., Pilot, sum)



More information about the R-help mailing list