| var_grid | R Documentation |
xvars and yvars arguments are tidyselect expressions (see
tidyselect syntax) that
specify the columns of x whose names will be used as a domain for
combinations.
If yvars is NULL, the function creates a tibble with one column var
enumerating all column names specified by the xvars argument.
If yvars is not NULL, the function creates a tibble with two columns,
xvar and yvar, whose rows enumerate all combinations of column names
specified by the xvars and yvars argument.
It is allowed to specify the same column in both xvars and yvars
arguments. In such a case, the combinations of the same column with itself
are removed from the result.
In other words, the function creates a grid of all possible pairs
(xx, yy) where xx \in xvars, yy \in yvars,
and xx \neq yy.
var_grid(
x,
xvars = everything(),
yvars = everything(),
allow = "all",
xvar_name = if (quo_is_null(enquo(yvars))) "var" else "xvar",
yvar_name = "yvar",
error_context = list(arg_x = "x", arg_xvars = "xvars", arg_yvars = "yvars", arg_allow =
"allow", arg_xvar_name = "xvar_name", arg_yvar_name = "yvar_name", call =
current_env())
)
x |
either a data frame or a matrix |
xvars |
a tidyselect expression (see
tidyselect syntax)
specifying the columns of |
yvars |
|
allow |
a character string specifying which columns are allowed to be
selected by
|
xvar_name |
the name of the first column in the resulting tibble. |
yvar_name |
the name of the second column in the resulting tibble.
The column does not exist if |
error_context |
A list of details to be used in error messages.
This argument is useful when
|
if yvars is NULL, the function returns a tibble with a single
column (var). If yvars is a non-NULL expression, the function
returns two columns (xvar and yvar) with rows enumerating
all combinations of column names specified by tidyselect expressions
in xvars and yvars arguments.
Michal Burda
# Create a grid of combinations of all pairs of columns in the CO2 dataset:
var_grid(CO2)
# Create a grid of combinations of all pairs of columns in the CO2 dataset
# such that the first, i.e., `xvar` column is `Plant`, `Type`, or
# `Treatment`, and the second, i.e., `yvar` column is `conc` or `uptake`:
var_grid(CO2, xvars = Plant:Treatment, yvars = conc:uptake)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.