Samples rows from a data frame with replacement, which preserves the
joint distribution of the selected attributes, and renders each sampled
row as a persona. This is the joint-distribution counterpart of
panel_from_margins(), which samples attributes independently. The
margins the report cites are computed from the source data, one
prop.table(table()) per selected column.
Arguments
- data
A data frame, one row per source case.
- n
Panel size.
- persona_template
Text with
{attribute}placeholders rendered per persona.NULLbuilds a plain "attribute: value" persona.- columns
Attribute columns to keep. Defaults to every column except the
weightscolumn when one is given.- weights
Optional name of a single column of nonnegative sampling weights (rows are drawn with probability proportional to it).
Examples
set.seed(110)
src <- data.frame(
education = c("college", "college", "no college", "no college"),
income = c("high", "high", "low", "low"),
weight = c(2, 2, 1, 1))
panel_from_data(src, n = 10, columns = c("education", "income"),
weights = "weight",
persona_template = "A {education} respondent earning {income}.")