Thank you both for your reply. I went with the cosine function for similarity
and used it with apply to get a measure of distance.
Ravi
--
View this message in context:
http://r.789695.n4.nabble.com/Distance-between-a-vector-and-matrix-rows-tp3726268p3726610.html
Sent from the R help mailing lis
Hi Ravi,
I don't know about other packages to calculate euclidian distances but
this can be done rather easily by hand:
ref<-rep(1,5)
apply(mydata,1,function(x)sqrt(sum((x-ref)^2)))
cheers
Am 08.08.2011 09:02, schrieb vioravis:
> I am trying to find the distance between a vector and each row of
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 wrote:
> I am trying to find the distance between a vector and each row of a
> dataframe. I am using the function "distance
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<-distan
4 matches
Mail list logo