search for: colnb

Displaying 1 result from an estimated 1 matches for "colnb".

Did you mean: colab
2010 Feb 12
3
Code working but too slow, any idea for how to speed it up ?(no loop in it)
...that is taking too long (2 seconds and I call him 720 times --> 12 minutes): mat1 and mat2 are both matrix with 103 columns and 164 rows. sequence <- matrix(seq(1 : ncol(mat1))) returns <- apply(sequence, 1, function, mat1= mat1, mat2 = mat2, day = 1) function<- function(mat1, mat2, colNb, day){ mat1<- matrix(mat1[, colNb] ) mat2<- matrix(mat2[, colNb]) nbDays <- length(mat1) returns <- abs(mat1[1:(nbDays - day)]) * ((as.ts(lag(mat2, day))/as.ts(mat2))^mat1[1:(nbDays - day)] - 1) return(returns) } I am wondering if the fact of usin...