Skip to content

distance between two matrices

2 messages · "Hüsing, Johannes", Brian Ripley

#
whoops; so is the choice between both a matter of style? Or is
it implementation-specific for R, and not generally true for S?

(I know from LISP that if using map, roughly the equivalent to
S' apply instead of the do loop, you cannot rely on the elements 
being executed in their original order, which might buy you 
efficiency depending on the implementation.)
#
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.