Re: [R] Create a new dataframe from an existing dataframe

From: Duncan Murdoch <>
Date: Mon, 07 Jan 2008 14:06:50 -0500

On 1/7/2008 1:28 PM, Gang Chen wrote:
> I have a dataframe DF with 4 columns (variables) A, B, C, and D, and
> want to create a new dataframe DF2 by keeping B and C in DF but
> counting the frequency of D while collapsing A. I tried
> by(DF$D, list(DF$B, DF$C), FUN=summary)
> but this is not exactly what I want. What is a good way to do it?

I think you can't do that. If you want to keep B and C, then you can't reduce the number of rows, but "collapsing A" sounds like you want fewer rows.

Perhaps if you posted a simple before and after example?

Duncan Murdoch mailing list PLEASE do read the posting guide and provide commented, minimal, self-contained, reproducible code. Received on Mon 07 Jan 2008 - 19:10:55 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Mon 07 Jan 2008 - 20:30:05 GMT.

Mailing list information is available at Please read the posting guide before posting to the list.

list of date sections of archive