Re: [R] comparison of two vectors

From: Ben Bolker <bolker_at_ufl.edu>
Date: Tue, 4 Dec 2007 11:57:09 -0800 (PST)

Daniel Stepputtis wrote:
>
> Dear Ben,
> I was searching for the same problem. Thank you very much, it helped me a
> lot and I will use it quite often!
>
> In addition to the problem given by tintin_et_milou. I have to compare a
> two pairs of vectors.
>
> I.e. I have two datasets each with latitude and longitude (which defines
> the geographical position of data points.)
> As you might imagine, it is meaningful to take into account both latitude
> and longitude, when searching for the nearest data point from the otehr
> dataset.
>
> Do you have any idea how to do this efficiently (actually I used loops ;-(
> ?
> Best regards
> Daniel
>
>
> Ben Bolker schrieb:

>> 
>> distfun <- function(x1,x2) { (x1-x2)^2 }
>> 
>> outer(m1[,1],y,distfun)

>
>>   cheers
>>     Ben

>

  Maybe (untested)

  distfun <- function(i,j) { (x1[i]-x2[j])^2 + (y1[i]-y2[j])^2) } outer(i,j,distfun)

  ?

-- 
View this message in context: http://www.nabble.com/comparison-of-two-vectors-tf4936213.html#a14158136
Sent from the R help mailing list archive at Nabble.com.

______________________________________________
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 Tue 04 Dec 2007 - 20:01:23 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 Tue 04 Dec 2007 - 21:30:17 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.