Re: [R] Efficient way to substract all entries in two vectors from each other

2008-01-07 Thread Johannes Graumann
Ido M. Tamir wrote: > matchpt Thanks for this hint. It is exactly what I'm looking for. Cheers, Joh __ 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-guid

Re: [R] Efficient way to substract all entries in two vectors from each other

2008-01-07 Thread Ido M. Tamir
Johannes Graumann wrote: > Hi all, > > I'm to inexperienced to come up with the matrix solution elusively > appearing on the horizon for the following problem and would appreciate if > you could give me a nudge ... > I have two vectors a, and b and need to find the closest match for each > value

Re: [R] Efficient way to substract all entries in two vectors from each other

2008-01-07 Thread Talbot Katz
Hi Joh. To echo Bert, more detail would be helpful. But here is a stab at something. Given two numeric vectors, a and b, for each entry of a this finds the index in b of the closest match. It's not efficient at all. > bestmati <- function( a, b ) { return( sapply( a, function( x ) { which.m

[R] Efficient way to substract all entries in two vectors from each other

2008-01-07 Thread Johannes Graumann
Hi all, I'm to inexperienced to come up with the matrix solution elusively appearing on the horizon for the following problem and would appreciate if you could give me a nudge ... I have two vectors a, and b and need to find the closest match for each value of a in b. How to do that efficiently?