[R] Using tapply to create a new table

From: Kalish, Josh <josh.kalish_at_credit-suisse.com>
Date: Fri 26 Jan 2007 - 17:39:29 GMT


All,

I'm sure that this is covered somewhere, but I can't seem to find a good explanation. I have an existing table that contains information grouped by date. This is as so:

Day		NumberOfCustomers		NumberOfComplaints
20060512	10040				40
20060513	32420				11

...

I also have a table at the detail level as so:

Day		Meal		PricePaid	UsedCupon
20060512	Fish		14		Y
20060512	Chicken	20		N

...

Is there a simple way to create summaries on the detail table and then join them into the first table above so that it looks like this:

Day NumberOfCustomers NumberOfComplaints AveragePricePaid NumberUsingCupon

I can do a tapply to get what I want from the detail table, but I can't figure out how to turn that into a table and join it back in.

Thanks,

Josh



Please access the attached hyperlink for an important electr...{{dropped}}

R-help@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. Received on Sat Jan 27 05:00:11 2007

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Fri 26 Jan 2007 - 18:30:30 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.