This function converts a data frame to a matrix with the same number of rows. For any two rows of the resulting matrix, the Manhattan distance equals the Gower distance in the input data between the corresponding rows.

mangow(data)

Arguments

data

The input data frame with continuous, categorical (factor) and ordered variables

Value

A numeric matrix

Examples

iris_sub <- iris[c(1:2,50:51,100:101), ] row.names(iris_sub) <- NULL iris_sub
#> Sepal.Length Sepal.Width Petal.Length Petal.Width Species #> 1 5.1 3.5 1.4 0.2 setosa #> 2 4.9 3.0 1.4 0.2 setosa #> 3 5.0 3.3 1.4 0.2 setosa #> 4 7.0 3.2 4.7 1.4 versicolor #> 5 5.7 2.8 4.1 1.3 versicolor #> 6 6.3 3.3 6.0 2.5 virginica
cluster::daisy(iris_sub, "gower")
#> Dissimilarities : #> 1 2 3 4 5 #> 2 0.16190476 #> 3 0.06666667 0.09523810 #> 4 0.71449275 0.70496894 0.66687371 #> 5 0.67018634 0.54637681 0.62256729 0.27287785 #> 6 0.77142857 0.81904762 0.72380952 0.44741201 0.58695652 #> #> Metric : mixed ; Types = I, I, I, I, N #> Number of objects : 6
mangow_iris_sub <- mangow(iris_sub) cluster::daisy(mangow_iris_sub, "manhattan")
#> Dissimilarities : #> 1 2 3 4 5 #> 2 0.16190476 #> 3 0.06666667 0.09523810 #> 4 0.71449275 0.70496894 0.66687371 #> 5 0.67018634 0.54637681 0.62256729 0.27287785 #> 6 0.77142857 0.81904762 0.72380952 0.44741201 0.58695652 #> #> Metric : manhattan #> Number of objects : 6