Learn R Programming

dfmirroR (version 2.2.0)

simulate_dataframe: Simulate data that mirrors a data frame and output code to re-create the simulation

Description

Simulate data that mirrors a data frame and output code to re-create the simulation

Usage

simulate_dataframe(
  input_df,
  num_obs = 1,
  columns_to_simulate = colnames(input_df),
  hide_cols = FALSE,
  seed = NULL
)

Value

A list with

  • simulated_df a data frame object containing a simulated mirror of the input df where each specified column has the same mean and standard deviation as the input df

  • code a string vector that can be run in conjunction with cat() to output easily shareable code to recreate simulated_df

Arguments

input_df

A data frame.

num_obs

A numeric value specifying how many observations (i.e., rows) to simulate.

columns_to_simulate

One or more columns from the input_df to simulate. The default is all columns.

hide_cols

Select TRUE to replace column names with anonymized names that take the form of "v1," "v2," and so on for each column.

seed

Optional random seed for reproducibility

Examples

Run this code
# # Run the function and create an object called `mirrored_df`
mirrored_df <- simulate_dataframe(mtcars, num_obs = 10, columns_to_simulate = c("mpg", "wt"))

# Print the mirrored data frame
print(mirrored_df$simulated_df)

# Output code to create the mirrored data frame for asking
# questions or supporting other reproducible tasks
cat(mirrored_df$code)

Run the code above in your browser using DataLab