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

From: Henrique Dallazuanna <wwwhsd_at_gmail.com>
Date: Mon, 7 Jan 2008 15:52:24 -0200

Try this:

 b[which.min(a-b)]

On 07/01/2008, Johannes Graumann <johannes_graumann_at_web.de> wrote:
> Vectors are numerics. I'd like to know for each a[i], which b[j] delivers
> the smallest abs(a[i]-b[j]).
>
> Thanks for your time.
>
> Joh
>
> Bert Gunter wrote:
>
> > Vectors of what? How is "closest" defined? See e.g. ?dist
> >
> >
> > Bert Gunter
> > Genentch Nonclinical Statistics
> >
> >
> > -----Original Message-----
> > From: r-help-bounces_at_r-project.org [mailto:r-help-bounces_at_r-project.org]
> > On Behalf Of Johannes Graumann
> > Sent: Monday, January 07, 2008 11:19 AM
> > To: r-help_at_stat.math.ethz.ch
> > Subject: [R] Efficient way to substract all entries in two vectors from
> > eachother
> >
> > 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?
> >
> > Thanks, Joh
> >
> > ______________________________________________
> > R-help_at_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-guide.html and provide commented,
> > minimal, self-contained, reproducible code.
> >
> > ______________________________________________
> > R-help_at_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-guide.html and provide commented,
> > minimal, self-contained, reproducible code.
>
> ______________________________________________
> R-help_at_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-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O

______________________________________________
R-help_at_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-guide.html
and provide commented, minimal, self-contained, reproducible code.
Received on Mon 07 Jan 2008 - 17:55:43 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Mon 07 Jan 2008 - 18:30:05 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive