[R] pair matching

2009-05-12 Thread Thomas S. Dye
Given two numeric vectors of possibly unequal length, I'd like to pair each element of the shorter vector with an element of the longer vector such that the sum of squared differences between the pairs is minimized. Can someone point me to an R function or an algorithm for accomplishing

Re: [R] pair matching

2009-05-12 Thread Liaw, Andy
If the matching need not be one-to-one, then you can just compute the Euclidean distances between the two vectors, then in each row (or column, which ever corresponds to the shorter vector) and find the smallest. This should be fairly easy to do. Andy From: Thomas S. Dye Given two numeric

Re: [R] pair matching

2009-05-12 Thread David Winsemius
[order(df$dist),], min(length(a),length(b)) ) Var1 Var2 dist 2 2 2 0 6 3 3 0 1 1 2 1 -- David Winsemius - Original Message - From: Thomas S. Dye t...@tsdye.com To: r-help@r-project.org Sent: Tuesday, May 12, 2009 10:02:29 AM GMT -08:00 US/Canada Pacific Subject: [R] pair matching

[R] pair matching query corrected

2009-05-12 Thread Thomas S. Dye
I posed this question imprecisely earlier and did not specify that the pairing needs to be one-to-one. A precise version of the question follows: Given two numeric vectors of possibly unequal length, I'd like to pair each element of the shorter vector with an element of the longer vector