[R] Create a new dataframe from an existing dataframe

Duncan Murdoch murdoch at stats.uwo.ca
Mon Jan 7 20:06:50 CET 2008


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




More information about the R-help mailing list