Skip to content
Prev 325557 / 398503 Next

find closest value in a vector based on another vector values

Jorge: No.
[1]  8 32  ##should be  8   33.5

I believe it has to be done explicitly by finding all the differences
and choosing those n with minimum values, depending on what n you
want.

Note that the problem is incompletely specified. What if the same
value of a is closest to several values of b? -- do you want all the
values you choose to be different or not, in which case they may not
be minimum?

a <- c(1, 8, 9)
b <- c(2,3)

Then what are the 2 closest values of a to b?

-- Bert
On Tue, Jun 18, 2013 at 5:43 AM, Jorge I Velez <jorgeivanvelez at gmail.com> wrote: