[R] R 2.3.1 on Mac OSX: apply a function to 'dist()' ?

From: Hans-Joerg Bibiko <bibiko_at_eva.mpg.de>
Date: Wed 05 Jul 2006 - 23:55:47 EST

Dear all,

maybe there is someone who has an hint for me.

I have to calculate a distance matrix by using my own function to get the distance between two rows of my matrix.

The normal way to do this is to use two 'for loops' like

for(i in 1:nrow)

   for(j in i:nrow)
     _my_function(matrix[i,],matrix[j,])

OK. This works, but unfortunately I have a very huge matrix and it takes hours even on a cpu-cluster.

My question is:

Is there any chance to increase the speed of doing this? My first idea was to apply my function to 'dist()' like 'outer (x,y,"fun")'. But up to know there is no implementation for that(?) and I don't know whether it would increase the speed. On the other hand it would be possible to write a C-routine for that, but I have to use several function to calculate the distance and some other people who want to use this algorithm aren't familiar with C.

I would be pleased if there are any hints!

Many thanks in advance!

Cheers,

Hans



R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Thu Jul 06 00:12:07 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Thu 06 Jul 2006 - 02:18:16 EST.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.