Learn R Programming

rsdv (version 0.2.0)

sample: Sample synthetic rows from a fitted synthesizer

Description

Dispatches to the synthesizer-specific method when x is an rsdv_synthesizer. For plain R vectors, integers, or characters it falls back to base::sample(), preserving backward compatibility.

Usage

sample(x, n = NULL, ...)

Value

When x inherits from rsdv_synthesizer, a data frame of n

synthetic rows whose columns match the metadata. When x is any other object, the value returned by base::sample() — typically a vector of the same type as x and length n.

Arguments

x

A fitted synthesizer object, or a vector for base::sample() compat.

n

Number of synthetic rows to generate (synthesizer path), or sample size (base::sample path).

...

Additional arguments passed to the method or to base::sample().

Examples

Run this code
# Falls back to base::sample for non-synthesizer objects:
sample(1:10, 3)

# \donttest{
meta  <- metadata(adult_income) |>
  set_column_type("age",    "numerical") |>
  set_column_type("income", "categorical")
syn   <- gaussian_copula_synthesizer(meta) |> fit(adult_income)
synth <- sample(syn, n = 100)
head(synth)
# }

Run the code above in your browser using DataLab