Description Usage Arguments Details Value Examples
calculatePrice()
calculates the best price of the
existing shopping cart. That means at first every meaningful combination of
any discount offers is calculated. Than the cheapest way is filtered and
returned. This functions acts as a convenient wrapper for the functions
analyseShoppingCart()
, enumerateCombinations()
,
extractDiscountSets()
and calculateBestDiscount()
.
1 2 | calculatePrice(shoppingCart, discountInfos, pricePerItem,
intermediateSteps = FALSE)
|
shoppingCart |
shopping cart as an data.frame with one row for one item |
discountInfos |
|
pricePerItem |
numerical price for one item; Currently only one price is allowed |
intermediateSteps |
if it's set to |
Currently the argument discountInfos
needs one special format: It
needs two columns:
1. The first one is called set
and contains numerical information
about the discount sets' possibilities (read examples
)
2. The second one is called discount
and contains numerical
information about the discount.
Further the argument shoppingCart
requires some specific formatting,
since no generalisation has been implemented yet (analyseShoppingCart
already has this generalisation). These requirements are:
1. shoppingCart
need to be a data.frame
with...
2. ...two columns. The first need to be called itemID
and contains the
ID of every item. The second one is named name
and contains the
name of the item.
Depending on intermediateSteps
, only a numerical vector is
returned or a list which additionally contains the intermediate steps.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | ```
# These books are available in the shop
books <- dplyr::tibble(
itemID = 1:5,
name = c(
"Stein der Weisen",
"Kammer des Schreckens",
"Gefangene von Askaban",
"Feuerkelch",
"Orden des Phönix"
)
)
set.seed(1)
shoppingCart <- dplyr::sample_n(books, 15, replace = TRUE) %>%
dplyr::arrange(itemID)
discountTibble <- dplyr::tibble(
set = 1:5,
discount = c(0, 5, 10, 20, 25)
)
calculatePrice(shoppingCart, discountTibble, pricePerItem = 8)
```
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.