Description Usage Arguments See Also Examples
View source: R/pairwise_dist.R
Compute distances of all pairs of items in a tidy table.
1 2 3 | pairwise_dist(tbl, item, feature, value, method = "euclidean", ...)
pairwise_dist_(tbl, item, feature, value, method = "euclidean", ...)
|
tbl |
Table |
item |
Item to compare; will end up in |
feature |
Column describing the feature that links one item to others |
value |
Value |
method |
Distance measure to be used; see |
... |
Extra arguments passed on to |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | library(gapminder)
library(dplyr)
# closest countries in terms of life expectancy over time
closest <- gapminder %>%
pairwise_dist(country, year, lifeExp) %>%
arrange(distance)
closest
closest %>%
filter(item1 == "United States")
# to remove duplicates, use upper = FALSE
gapminder %>%
pairwise_dist(country, year, lifeExp, upper = FALSE) %>%
arrange(distance)
# Can also use Manhattan distance
gapminder %>%
pairwise_dist(country, year, lifeExp, method = "manhattan", upper = FALSE) %>%
arrange(distance)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.