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? Thanks, Gang
Duncan Murdoch
2008-Jan-07 19:06 UTC
[R] Create a new dataframe from an existing dataframe
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