add_var_random_cat: Add a random categorical variable to dataset

View source: R/add-var.R

add_var_random_catR Documentation

Add a random categorical variable to dataset

Description

Add a random categorical variable to dataset

Usage

add_var_random_cat(
  data,
  name = "random_cat",
  cat = LETTERS[1:6],
  prob,
  overwrite = TRUE,
  seed
)

Arguments

data

A dataset

name

Name of new variable (as string)

cat

Vector of categories

prob

Vector of probabilities

overwrite

Can new random variable overwrite an existing variable in dataset?

seed

Seed for random number generation (integer)

Value

Dataset containing new random variable

Examples

library(magrittr)
iris %>% add_var_random_cat() %>% head()
iris %>% add_var_random_cat(name = "my_cat") %>% head()
iris %>% add_var_random_cat(cat = c("Version A", "Version B")) %>% head()
iris %>% add_var_random_cat(cat = c(1,2,3,4,5)) %>% head()

explore documentation built on Sept. 11, 2024, 7:40 p.m.