[R] Distance between a vector and matrix rows

Dennis Murphy djmuser at gmail.com
Mon Aug 8 11:16:42 CEST 2011


Hi:

> sqrt(0.2)
[1] 0.4472136

Evidently, distancevector() is finding the *average* distance between
the two vectors.

HTH,
Dennis

On Mon, Aug 8, 2011 at 12:02 AM, vioravis <vioravis at gmail.com> wrote:
> I am trying to find the distance between a vector and each row of a
> dataframe. I am using the function "distancevector" in the package "hopach"
> as follows:
>
> mydata<-as.data.frame(matrix(c(1,1,1,1,0,1,1,1,1,0),nrow=2))
>
>  V1 V2 V3 V4 V5
> 1  1  1  0  1  1
> 2  1  1  1  1  0
> vec <- c(1,1,1,1,1)
> d2<-distancevector(mydata,vec,d="euclid")
>
> The Euclidean distance between the two rows of the data frame to the vector
> should be 1. But I am getting 0.4472136 for both.
>
> Can someone please point out the reason for the discrepancy???
>
> Also, are there other packages for calculating the distance between a binary
> vector and all the rows of a data frame (contains only binary values)?
>
> Thank you.
>
> Ravi
>
> --
> View this message in context: http://r.789695.n4.nabble.com/Distance-between-a-vector-and-matrix-rows-tp3726268p3726268.html
> 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.
>



More information about the R-help mailing list