Re: [R] how to calculate another vector based on the data from a combination of two factors

2008-11-17 Thread jeffc
Hi All, Thank all for the input. These different solutions rock!. Hao -- View this message in context: http://www.nabble.com/how-to-calculate-another-vector-based-on-the-data-from-a-combination-of-two-factors-tp20532749p20553226.html Sent from the R help mailing list archive at Nabble.com. __

Re: [R] how to calculate another vector based on the data from a combination of two factors

2008-11-16 Thread Jorge Ivan Velez
Dear Jeff, Try also df=df[order(df$State, df$Gender), ] df$cQuantity<-unlist(tapply(df[,3],df[,-3],cumsum)) df State Gender Quantity cQuantity 2NY Female2 2 4NY Female4 6 1TX Male1 1 3TX Male3 4 HTH, Jorge

Re: [R] how to calculate another vector based on the data from a combination of two factors

2008-11-16 Thread hadley wickham
On Sun, Nov 16, 2008 at 8:12 PM, jeffc <[EMAIL PROTECTED]> wrote: > > Hi, > > I have a data set similar to the following > > State Gender Quantity > TX Male1 > NY Female 2 > TX Male3 > NY Female 4 > > > I need to calculate cumulative sum of the quantity by State and

Re: [R] how to calculate another vector based on the data from a combination of two factors

2008-11-16 Thread Gabor Grothendieck
Try this. The first line appends the cumulative sum column and the second displays it in sorted fashion: DF$cumQuantity <- ave(DF$Quantity, DF$State, DF$Gender, FUN = cumsum) DF[order(DF$State, DF$Gender), ] On Sun, Nov 16, 2008 at 9:12 PM, jeffc <[EMAIL PROTECTED]> wrote: > > Hi, > > I have a

Re: [R] how to calculate another vector based on the data from a combination of two factors

2008-11-16 Thread Marc Schwartz
on 11/16/2008 08:12 PM jeffc wrote: > Hi, > > I have a data set similar to the following > > State Gender Quantity > TXMale1 > NYFemale 2 > TXMale3 > NYFemale 4 > > > I need to calculate cumulative sum of the quantity by State and Gender. The > expected output is >

[R] how to calculate another vector based on the data from a combination of two factors

2008-11-16 Thread jeffc
Hi, I have a data set similar to the following State Gender Quantity TX Male1 NY Female 2 TX Male3 NY Female 4 I need to calculate cumulative sum of the quantity by State and Gender. The expected output is State Gender QuantityCumQuantity TX M