View source: R/lib_synthetic.R
| make_synthetic_column | R Documentation |
Builds a single synthetic data column according to a column spec drawn
from a provenance synthetic recipe. Supported types are "sample"
(categorical, optionally weighted), "bernoulli" (two-label draw with
optional per-row base rate), "poisson" (counts with a floor),
"id_pattern" (templated IDs, optionally per-year sequenced), and
"sequence" (a running integer sequence).
make_synthetic_column(spec, n, ctx = list(), base_p = NULL)
spec |
A list describing the column; recognised fields depend on
|
n |
Number of values to generate. |
ctx |
Named list of already-generated columns, letting later
columns (such as |
base_p |
Optional numeric vector of per-row latent propensities
used by the |
A vector of length n for the requested column type. Errors on
an unknown type.
set.seed(1)
# "sample": categorical draw, optionally weighted.
make_synthetic_column(list(type = "sample", values = list("a", "b"),
weights = list(0.7, 0.3)), 5)
# "bernoulli": two-label draw at probability p.
make_synthetic_column(list(type = "bernoulli", p = 0.5,
labels = list("Yes", "No")), 5)
# "poisson": counts with a floor via `min`.
make_synthetic_column(list(type = "poisson", lambda = 3, min = 1), 5)
# "id_pattern": templated IDs (the {seq:05d} token is zero-padded).
make_synthetic_column(list(type = "id_pattern",
pattern = "case-{seq:05d}"), 3)
# "sequence": a running integer sequence from `from`.
make_synthetic_column(list(type = "sequence", from = 100), 4)
# An unknown type errors.
try(make_synthetic_column(list(type = "nope"), 3))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.