widely | R Documentation |
Modify a function in order to pre-cast the input into a wide matrix format, perform the function, and then re-tidy (e.g. melt) the output into a tidy table.
widely(.f, sort = FALSE, sparse = FALSE, maximum_size = 1e+07) widely_(.f, sort = FALSE, sparse = FALSE, maximum_size = 1e+07)
.f |
Function being wrapped |
sort |
Whether to sort in descending order of |
sparse |
Whether to cast to a sparse matrix |
maximum_size |
To prevent crashing, a maximum size of a non-sparse matrix to be created. Set to NULL to allow any size matrix. |
Returns a function that takes at least four arguments:
tbl |
A table |
row |
Name of column to use as rows in wide matrix |
column |
Name of column to use as columns in wide matrix |
value |
Name of column to use as values in wide matrix |
... |
Arguments passed on to inner function |
widely
creates a function that takes those columns as
bare names, widely_
a function that takes them as strings.
library(dplyr) library(gapminder) gapminder gapminder %>% widely(dist)(country, year, lifeExp) # can perform within groups closest_continent <- gapminder %>% group_by(continent) %>% widely(dist)(country, year, lifeExp) closest_continent # for example, find the closest pair in each closest_continent %>% top_n(1, -value)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.