search for: size_mtx

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

Did you mean: size_max
2004 Nov 25
4
Avoiding for-loops
...two for-loops but it doens't seem to be a clever way, and I'd like to know a more efficient code for a large matrix of thousands of rows and columns. Below is my code for your reference. Thanks a lot. John #################### # mtx.sym is a symmetric matrix > my.ftn <- function(size_mtx, mtx) { + my.vector <- c() + for ( i in 1:size_mtx ) { + cat(".") + for ( j in 1:size_mtx ) { + if ( upper.tri(mtx)[i,j] ) { + my.vector <- c(my.vector, mtx[i,j]) + }}} + cat("\n") + } > # if I have a matrix, mtx.sym, of 100x100 > my.ftn(100, mtx.sym)