Skip to content

Calculating just a single row of dissimilarity/distance matrix

1 message · Jan van der Laan

#
Please respond to the list; there are more people answering there.


As explained in the documentation gower_dist performes a pairwise 
comparison of the two arguments recycling the shortest one if needed, so 
indeed gower_dist(iris[1:5, ], iris) doesn't do what you want.

Possible solutions are:

tmp <- split(iris[1:150, ], seq_len(150))

sapply(gower_dist, iris)


and:


library(dplyr)

library(tidyr)

pairs <- expand.grid(x = 1:5, y = 1:nrow(iris))
pairs$dist <- gower_dist(iris[pairs$x, ], iris[pairs$y, ])
pairs %>% spread(y, dist)

Don't know which one is faster. And there are probably various other 
solutions too.

--
Jan
On 27-10-18 18:04, Aerenbkts bkts wrote: