The function normalizes grammage units of products and recalculates product prices and quantities with respect to these normalized grammage units.
data_norm(
data = data.frame(),
rules = list(c("ml", "l", 1000), c("g", "kg", 1000)),
all = TRUE
)
The function returns the user's data frame with two transformed columns: grammage
and unit
, and two rescaled columns: prices
and quantities
. The above-mentioned transformation and rescaling take into consideration the user rules
. Recalculated prices and quantities concern grammage units defined as the second parameter in the given rule.
The user's data frame. The data frame must contain the following columns: prices
(as positive numeric), quantities
(as positive numeric), grammage
(as numeric or character) and unit
(as character).
User rules for transforming grammage
, unit
, prices
and quantities
of products. For instance, a rule ("ml","l",1000)
changes the 'old' grammage unit: ml
into the new one: l
on the basis of the provided relation: 1000ml=1l
. As a consequence, for each product which is sold in liters l
, the unit price and quantity are calculated.
A logical value indicating whether the resulting data frame is to be limited to products with detected grammage. Its default value is TRUE
which means that not transformed rows (products) are also returned.
# Preparing a data set
data<-data_unit(dataU,units=c("g","ml","kg","l"),multiplication="x")
# Normalization of grammage units
data_norm(data, rules=list(c("ml","l",1000),c("g","kg",1000)))
Run the code above in your browser using DataLab