select_products: Randomly select products

View source: R/select_products.R

select_productsR Documentation

Randomly select products

Description

Randomly select products to include in customers' baskets, possible with varying probabilities for different products. This function is meant to randomize/stimulate a 'grocery shopping experience', assuming the number of products per basket/order is randomly distributed.

Usage

select_products(
  products,
  probs,
  customer_id,
  min_products,
  mean_products,
  sd_products
)

Arguments

products

Vector of products to select from.

probs

Probabilities of selecting products.

customer_id

Vector of customer id's.

min_products

Minimum number of products per basket/order.

mean_products

Average number of products per basket/order.

sd_products

Standard deviation for number of products per basket/order.

Value

A vector of product names.

Examples

# 7 products to choose from
items <- c("apple", "orange", "tea", "coffee", "ice cream", "cookie", "jam")

# 3 customers
c_id <- 1:3

# All products are equally likely to be chosen
baskets <- select_products(items, rep(1/7, length(items)),
customer_id = c_id, min_products = 1, mean_products = 3, sd_products = 1)

# Table of customers and their baskets
tibble::tibble(customer_id = c_id, order = baskets) %>%
tidyr::separate_rows(order, sep = "@")

moamiristat/grocerycart documentation built on June 15, 2022, 10 a.m.