[R] Linearize a Function

From: Gottfried Gruber <ggruber_at_terminal.at>
Date: Wed 25 Jan 2006 - 09:11:13 EST


i calculate the log-returns in return1 and i want to get the performance for the security. with only one security i have the following code

# create matrix to keep performance

# matrix for the sum

# suming up the returns from current index to start
for (i in 1:length(return1)) {z1[i+1]=sum(return1[c(1:i)]) } #adding both matrices

this works fine for a 1 x n matrix, but if i want the same for a n x m matrix i assume the above code will get time-consuming. is there a trick to linearize the for-loop or any other solution?

thanks for any solution & effort,
tia gg

Gottfried Gruber
www: http://gogo.sehrsupa.net

R-help@stat.math.ethz.ch mailing list
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Received on Wed Jan 25 10:50:52 2006

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:42:10 EST