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.
__
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
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
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
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
>
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
6 matches
Mail list logo