Tidy summarizes information about the components of a model. A model component might be a single term in a regression, a single hypothesis, a cluster, or a class. Exactly what tidy considers to be a model component varies cross models but is usually self-evident. If a model has several distinct types of components, you will need to specify which components to return.

# S3 method for dist
tidy(x, diagonal = attr(x, "Diag"), upper = attr(x,
  "Upper"), ...)

Arguments

x

A dist object returned from stats::dist().

diagonal

Logical indicating whether or not to tidy the diagonal elements of the distance matrix. Defaults to whatever was based to the diag argument of stats::dist().

upper

Logical indicating whether or not to tidy the upper half of the distance matrix. Defaults to whatever was based to the upper argument of stats::dist().

...

Additional arguments. Not used. Needed to match generic signature only. Cautionary note: Misspelled arguments will be absorbed in ..., where they will be ignored. If the misspelled argument has a default value, the default value will be used. For example, if you pass conf.lvel = 0.9, all computation will proceed using conf.level = 0.95. Additionally, if you pass newdata = my_tibble to an augment() method that does not accept a newdata argument, it will use the default value for the data argument.

Details

If the distance matrix does not include an upper triangle and/or diagonal, the tidied version will not either.

See also

Value

A tibble::tibble() with columns:

distance

Distance between items

item1

First item

item2

Second item

Examples

iris_dist <- dist(t(iris[, 1:4])) iris_dist
#> Sepal.Length Sepal.Width Petal.Length #> Sepal.Width 36.15785 #> Petal.Length 28.96619 25.77809 #> Petal.Width 57.18304 25.86407 33.86473
tidy(iris_dist)
#> # A tibble: 6 x 3 #> item1 item2 distance #> <fct> <fct> <dbl> #> 1 Sepal.Width Sepal.Length 36.2 #> 2 Petal.Length Sepal.Length 29.0 #> 3 Petal.Width Sepal.Length 57.2 #> 4 Petal.Length Sepal.Width 25.8 #> 5 Petal.Width Sepal.Width 25.9 #> 6 Petal.Width Petal.Length 33.9
tidy(iris_dist, upper = TRUE)
#> # A tibble: 12 x 3 #> item1 item2 distance #> <fct> <fct> <dbl> #> 1 Sepal.Width Sepal.Length 36.2 #> 2 Petal.Length Sepal.Length 29.0 #> 3 Petal.Width Sepal.Length 57.2 #> 4 Sepal.Length Sepal.Width 36.2 #> 5 Petal.Length Sepal.Width 25.8 #> 6 Petal.Width Sepal.Width 25.9 #> 7 Sepal.Length Petal.Length 29.0 #> 8 Sepal.Width Petal.Length 25.8 #> 9 Petal.Width Petal.Length 33.9 #> 10 Sepal.Length Petal.Width 57.2 #> 11 Sepal.Width Petal.Width 25.9 #> 12 Petal.Length Petal.Width 33.9
tidy(iris_dist, diagonal = TRUE)
#> # A tibble: 10 x 3 #> item1 item2 distance #> * <fct> <fct> <dbl> #> 1 Sepal.Length Sepal.Length 0 #> 2 Sepal.Width Sepal.Length 36.2 #> 3 Petal.Length Sepal.Length 29.0 #> 4 Petal.Width Sepal.Length 57.2 #> 5 Sepal.Width Sepal.Width 0 #> 6 Petal.Length Sepal.Width 25.8 #> 7 Petal.Width Sepal.Width 25.9 #> 8 Petal.Length Petal.Length 0 #> 9 Petal.Width Petal.Length 33.9 #> 10 Petal.Width Petal.Width 0