View source: R/select_products.R
select_products | R Documentation |
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.
select_products( products, probs, customer_id, min_products, mean_products, sd_products )
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. |
A vector of product names.
# 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 = "@")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.