generate_df: Generate pseudorandom dataframes with specific parameters

View source: R/generate_df.R

generate_dfR Documentation

Generate pseudorandom dataframes with specific parameters

Description

This function is a small utility to create a specific length dataframe with a set number of groups, specific mean/sd per group. Note that the total length of the dataframe will be n * n_grps.

Usage

generate_df(n = 10L, n_grps = 1L, mean = c(10), sd = mean/10, with_seed = NULL)

Arguments

n

An integer indicating the number of rows per group, default to 10

n_grps

An integer indicating the number of rows per group, defaults to 1

mean

A number indicating the mean of the randomly generated values, must be a vector of equal length to the n_grps

sd

A number indicating the standard deviation of the randomly generated values, must be a vector of equal length to the n_grps

with_seed

A seed to make the randomization reproducible

Value

a tibble/dataframe

Function ID

2-19

See Also

Other Utilities: add_text_img(), fa_icon_repeat(), fmt_pad_num(), fmt_pct_extra(), fmt_symbol_first(), gt_add_divider(), gt_badge(), gt_double_table(), gt_duplicate_column(), gt_fa_column(), gt_fa_rank_change(), gt_fa_rating(), gt_fa_repeats(), gt_highlight_cols(), gt_highlight_rows(), gt_img_border(), gt_img_circle(), gt_img_multi_rows(), gt_img_rows(), gt_index(), gt_merge_stack_color(), gt_merge_stack(), gt_two_column_layout(), gtsave_extra(), img_header(), pad_fn(), tab_style_by_grp()

Examples

library(dplyr)
generate_df(
  100L,
  n_grps = 5,
  mean = seq(10, 50, length.out = 5)
) %>%
  group_by(grp) %>%
  summarise(
    mean = mean(values), # mean is approx mean
    sd = sd(values), # sd is approx sd
    n = n(), # each grp is of length n
    # showing that the sd default of mean/10 works
    `mean/sd` = round(mean / sd, 1)
  )

gtExtras documentation built on Sept. 16, 2023, 1:08 a.m.