xnew_data | R Documentation |
Generates a new data frame (in the form of a tibble)
xnew_data(.data, ..., .length_out = NULL)
.data |
The data frame to generate the new data from. |
... |
A list of variables to generate sequences for. |
.length_out |
NULL or a count specifying the maximum length of all sequences. |
By default, all specified variables vary across their range while all other variables are held constant at their reference value. Types, classes, factor levels and time zones are always preserved. The user can specify the length of each sequence, require that only observed values and combinations are used and add new variables.
xnew_value()
, xnew_seq()
, xcast()
and xobs_only()
data <- tibble::tibble(
period = factor(c("before", "before", "after", "after"),
levels = c("before", "after")
),
count = c(0L, 1L, 5L, 4L),
annual = factor(c(2, 3, 5, 8), levels = c(1, 2, 3, 5, 8))
)
# By default all other variables are held constant at their reference value.
xnew_data(data)
# Specifying a variable causes it to vary across its range.
xnew_data(data, annual)
# The user can specify the length of a sequence.
xnew_data(data, xnew_seq(annual, length_out = 3))
# And only allow observed values.
xnew_data(data, xnew_seq(annual, length_out = 3, obs_only = TRUE))
# With multiple variables all combinations are produced
xnew_data(data, period, xnew_seq(annual, length_out = 3, obs_only = TRUE))
# To only preserve observed combinations use
xnew_data(data, xobs_only(period, annual))
# And to cast the values use
xnew_data(data, xcast(annual = "3"))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.