[R] cumsum over varying column lengths

2007-03-16 Thread Murali Menon
Folks, I have a matrix of historicalReturns, where entry (i, j) is the daily return corresponding to date i and equity j. I also have a matrix startOffset, where entry (1, k) is the row offset in historicalReturns where I entered into equity k. So we have that NCOL(startOffset) =

Re: [R] cumsum over varying column lengths

2007-03-16 Thread jim holtman
This might work for you: returnsFromInception - sapply(1:NROW(historicalReturns), function(x){ cumsum(historicalReturns[startOffset[1, x] : n, x]) }) On 3/16/07, Murali Menon [EMAIL PROTECTED] wrote: Folks, I have a matrix of historicalReturns, where entry (i, j) is the daily return