new_data: Generate New Data

View source: R/new-data.R

new_dataR Documentation

Generate New Data

Description

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.

Usage

new_data(
  data,
  seq = character(0),
  ref = list(),
  obs_only = list(character(0)),
  length_out = 30
)

Arguments

data

The data frame to generate the new data from.

seq

A character vector of the variables in data to generate sequences for.

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.

Details

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.

Value

A tibble of the new data.

See Also

new_value() and new_seq().

Examples

# 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"))

poissonconsulting/newdata documentation built on Jan. 18, 2024, 1:30 a.m.