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
ar2)^2 )
head(df[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"
To: r-help@r-project.org
Sent: Tuesday, May 12, 2009 10:02:29 AM GMT -08:00 US/Canada Pacific
Subject: [R
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
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 th
4 matches
Mail list logo