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

2008-01-08 Thread Gang Chen
Yes, this works well. Also 'table' suggested by Bert Gunter also works perfectly. Thank all who've helped me on this. Gang On Jan 7, 2008, at 7:39 PM, jim holtman wrote: > Does this do what you want? > >> x <- read.table(textConnection("AB C D > + A1 B1 C1 D1 > + A1 B2 C1 D1 > + A1

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

2008-01-07 Thread jim holtman
Does this do what you want? > x <- read.table(textConnection("AB C D + A1 B1 C1 D1 + A1 B2 C1 D1 + A1 B1 C1 D1 + A1 B2 C2 D2 + A2 B1 C1 D1 + A1 B2 C2 D2 + A1 B1 C2 D2 + A2 B2 C1 D1 + A1 B1 C2 D2 + A2 B2 C1 D1"), header=TRUE) > counts <- ave(seq(nrow(x)), x$B, x$C, x$D, FUN=lengt

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

2008-01-07 Thread Gang Chen
Sorry the new column in DF2 should be called FreqD instead of FreqA. How can I get DF2 with aggregate? Gang On Jan 7, 2008, at 2:38 PM, Gang Chen wrote: > Yes, I misstated it when I said that I would keep B and C. I want to > collapse column A, but count the frequency of D as a new column in >

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

2008-01-07 Thread Bert Gunter
?table Bert Gunter Genentech Nonclinical Statistics -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Gang Chen Sent: Monday, January 07, 2008 11:38 AM To: Duncan Murdoch Cc: R-Help Subject: Re: [R] Create a new dataframe from an existing dataframe Yes

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

2008-01-07 Thread Gang Chen
Yes, I misstated it when I said that I would keep B and C. I want to collapse column A, but count the frequency of D as a new column in the new dataframe DF2 while collapsing A. The rows of columns B, C, and D of course would be reduced because of A collapsing. For example, if dataframe DF i

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

2008-01-07 Thread Duncan Murdoch
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

[R] Create a new dataframe from an existing dataframe

2008-01-07 Thread Gang Chen
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