pairwise_cor | R Documentation |
Find correlations of pairs of items in a column, based on a "feature" column that links them together. This is an example of the spread-operate-retidy pattern.
pairwise_cor( tbl, item, feature, value, method = c("pearson", "kendall", "spearman"), use = "everything", ... ) pairwise_cor_( tbl, item, feature, value, method = c("pearson", "kendall", "spearman"), use = "everything", ... )
tbl |
Table |
item |
Item to compare; will end up in |
feature |
Column describing the feature that links one item to others |
value |
Value column. If not given, defaults to all values being 1 (thus a binary correlation) |
method |
Correlation method |
use |
Character string specifying the behavior of correlations
with missing values; passed on to |
... |
Extra arguments passed on to |
library(dplyr) library(gapminder) gapminder %>% pairwise_cor(country, year, lifeExp) gapminder %>% pairwise_cor(country, year, lifeExp, sort = TRUE) # United Nations voting data if (require("unvotes", quietly = TRUE)) { country_cors <- un_votes %>% mutate(vote = as.numeric(vote)) %>% pairwise_cor(country, rcid, vote, sort = TRUE) }
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.