new_data | R Documentation |
Generates a new data frame (in the form of a tibble) with each variable
held constant or varying as a unique ordered sequence.
All possible unique combinations are included and the columns
are in the same order as those in data
.
new_data(
data,
seq = character(0),
ref = list(),
obs_only = list(character(0)),
length_out = 30
)
data |
The data frame to generate the new data from. |
seq |
A character vector of the variables in |
ref |
A named list of reference values for variables that are not in seq. |
obs_only |
A list of character vectors indicating the sets of variables to only allow observed combinations for. If TRUE then obs_only is set to be seq. |
length_out |
A count indicating the maximum length of sequences for all types of variables except logical, character, factor and ordered factors. |
If an element of ref
is a character vector and the corresponding
column is a data frame, then the ref element is assigned the same
factor levels as the column in the data. This is useful for choosing
a factor level without having to set the correct levels.
A tibble of the new data.
new_value()
and new_seq()
.
# an example data set
data <- tibble::tibble(
vecint = c(1L, 3L),
vecreal = c(1, 3),
vecchar = c("b", "a"),
vecdate = as.Date(c("2001-01-01", "2001-01-01"))
)
# vary count while holding other values constant
new_data(data, "vecint")
# vary continual
new_data(data, "vecreal")
new_data(data, c("vecchar", "vecint"))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.