Skip to content
Prev 43317 / 398506 Next

distance between two matrices

On Wed, 28 Jan 2004, "H?sing, Johannes" wrote:

            
It is not generally true for S.  The case studies in chapter 7 of `S 
Programming' show that efficient ways are implementation-dependent.

In some versions of S-PLUS (e.g. 3.4) apply was much faster and in some
(5.0) it was much slower.  Using lapply() (which has a C-level loop) is
sometimes rather faster in R.

In this particular example garbage collection is taking about 50% of time
of the pure R solution, so exactly what is done in what order can matter.  
knn1 is 20-30x faster since it works in place with space allocated just
once.