[R] Aggregate Help

David Winsemius dwinsemius at comcast.net
Thu Aug 19 23:01:53 CEST 2010


On Aug 19, 2010, at 4:45 PM, Hall, Ken (CDC/OSELS/NCPHI) 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

Perhaps:

with( Pilot, tapply(count, list(Date, illness), sum, na.rm=TRUE)

If you need it as a dataframe, then pass the result to:

?as.data.frame.table


>
> 2006/01/01	derm	52
> 2006/01/02	derm	104
> .
> .
> .
>
> And, the illness changes to fever with the same pattern.

Don't understand what that means.

> I would like to
> aggregate the same illnesses by date in the same fashion.

I thought that was what you asked for above.

>
> A nudge in the right direction would be appreciated.
>
> Thanks.
>
> Ken Hall
> Computer Scientist
> Division of Healthcare Information (DHI) (proposed)
> Public Health Surveillance Program Office (proposed)
> Office of Surveillance, Epidemiology, & Laboratory Services (OSELS)
>

Always interested in helping the CDC but I think you may need to be  
more expansive in your problem descriptions.

David Winsemius, MD
West Hartford, CT



More information about the R-help mailing list