[R] R 2.3.1 on Mac OSX: apply a function to 'dist()' ?
Hans-Joerg Bibiko
bibiko at eva.mpg.de
Wed Jul 5 15:55:47 CEST 2006
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
More information about the R-help
mailing list