[R] Adding elements in data.frame subsets and also subtracting an element from the rest elements in data.frame

2013-04-29 Thread Katherine Gobin
Dear R forum I have a data.frame as cashflow_df = data.frame(instrument = c(ABC,ABC,ABC,ABC,ABC,ABC,ABC,ABC,ABC,ABC,ABC,ABC,ABC,ABC, ABC, PQR, PQR, PQR,PQR,PQR,PQR,PQR,PQR,PQR,PQR, PQR, PQR, PQR,PQR, PQR,PQR,PQR,PQR, PQR,PQR,UVWXYZ,UVWXYZ, UVWXYZ, UVWXYZ, UVWXYZ,UVWXYZ,UVWXYZ,UVWXYZ, UVWXYZ,

Re: [R] Adding elements in data.frame subsets and also subtracting an element from the rest elements in data.frame

2013-04-29 Thread Bert Gunter
If this is a homework problem, there is a no homework policy on this list. -- Bert On Mon, Apr 29, 2013 at 5:24 AM, Katherine Gobin katherine_go...@yahoo.com wrote: Dear R forum I have a data.frame as cashflow_df = data.frame(instrument =

Re: [R] Adding elements in data.frame subsets and also subtracting an element from the rest elements in data.frame

2013-04-29 Thread arun
, April 29, 2013 8:24 AM Subject: [R] Adding elements in data.frame subsets and also subtracting an element from the rest elements in data.frame Dear R forum I have a data.frame as cashflow_df = data.frame(instrument = c(ABC,ABC,ABC,ABC,ABC,ABC,ABC,ABC,ABC,ABC,ABC,ABC,ABC,ABC, ABC, PQR, PQR

Re: [R] Adding elements in data.frame subsets and also subtracting an element from the rest elements in data.frame

2013-04-29 Thread arun
AM Subject: Re: [R] Adding elements in data.frame subsets and also subtracting an element from the rest elements in data.frame Hi Katherine, res1-aggregate(cbind(cashflow,cashflows_pv)~instrument+id,data=cashflow_df,sum) res2-res1[order(res1$instrument),]  res2$cashflow_change-with(res2,ave