Re: [R] Matrix/Vector manipulation

2011-10-04 Thread fernando.cabrera
0 > sum(ifelse(cumsum(W) <= 4, W, 0) * R) # ignores the 1*1.3 part because 3+2 > 4 [1] 3.6 Cheers, Fer -Original Message- From: David Reiner [mailto:david.rei...@xrtrading.com] Sent: 3. oktober 2011 17:57 To: Cabrera, Fernando Álvarez; r-help@r-project.org Subject: RE: [R] Matrix/

Re: [R] Matrix/Vector manipulation

2011-10-03 Thread fernando.cabrera
W) <= 4, W, 0) * R) # ignores the 1*1.3 part because 3+2 > 4 [1] 3.6 Cheers, Fer -Original Message- From: David Reiner [mailto:david.rei...@xrtrading.com] Sent: 3. oktober 2011 17:57 To: Cabrera, Fernando Álvarez; r-help@r-project.org Subject: RE: [R] Matrix/Vector manipulation sum(i

Re: [R] Matrix/Vector manipulation

2011-10-03 Thread David Reiner
sum(ifelse(cumsum(W)<=v, W, 0) * R) HTH, David L. Reiner -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of fernando.cabr...@nordea.com Sent: Monday, October 03, 2011 9:50 AM To: r-help@r-project.org Subject: [SPAM] - [R] Mat

[R] Matrix/Vector manipulation

2011-10-03 Thread fernando.cabrera
Hi guys, Have the following problem computing vectors with pure vector algebra and end up reverting to recursion or for-looping. Function my_cumsum calculates a weighted average (W) of ratios (R), but only up to the given size/volume (v). Now I recurse into the vector (from left to right) wit