Hi all. I'm developing a function, which must return a square matrix. Here is the code: http://pastebin.com/THzEW9N7
These functions implement an analog of two embedded for cycles. The first variant creates the resulting matrix by columns, cbind()-ing them one by one. The second variant creates the matrix with two columns, which rows contain all possible variants of i and j and calls apply on them. The test input (data frame cp.table) can be produced with the following commands: > n<-132 > cpt<-data.frame(x=runif(n, min=0, max=100), y=runif(n, min=0, max=100), > la=runif(n, min=0, max=360), phi=runif(n, min=-90, max=90)) Any random data will do. The second variant seems to me much more readable and beauteful. However, the first ugly variant runs much faster. Why?? Here are the profiles: -- View this message in context: http://r.789695.n4.nabble.com/More-simple-implementation-is-slow-tp4632872.html Sent from the R help mailing list archive at Nabble.com. ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.