(Deprecated) Tidy dist objects

# 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.

Value

A tibble::tibble with one row for each pair of items in the distance matrix, with columns:

item1

First item

item2

Second item

distance

Distance between items

Details

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

See also

Examples

cars_dist <- dist(t(mtcars[, 1:4])) cars_dist
#> mpg cyl disp #> cyl 89.32586 #> disp 1391.49546 1441.25177 #> hp 824.37547 878.17652 656.64044
tidy(cars_dist)
#> # A tibble: 6 x 3 #> item1 item2 distance #> <fct> <fct> <dbl> #> 1 mpg cyl 89.3 #> 2 mpg disp 1391. #> 3 mpg hp 824. #> 4 cyl disp 1441. #> 5 cyl hp 878. #> 6 disp hp 657.
tidy(cars_dist, upper = TRUE)
#> # A tibble: 12 x 3 #> item1 item2 distance #> <fct> <fct> <dbl> #> 1 mpg cyl 89.3 #> 2 mpg disp 1391. #> 3 mpg hp 824. #> 4 cyl mpg 89.3 #> 5 cyl disp 1441. #> 6 cyl hp 878. #> 7 disp mpg 1391. #> 8 disp cyl 1441. #> 9 disp hp 657. #> 10 hp mpg 824. #> 11 hp cyl 878. #> 12 hp disp 657.
tidy(cars_dist, diagonal = TRUE)
#> # A tibble: 10 x 3 #> item1 item2 distance #> <fct> <fct> <dbl> #> 1 mpg mpg 0 #> 2 mpg cyl 89.3 #> 3 mpg disp 1391. #> 4 mpg hp 824. #> 5 cyl cyl 0 #> 6 cyl disp 1441. #> 7 cyl hp 878. #> 8 disp disp 0 #> 9 disp hp 657. #> 10 hp hp 0