data_norm: Normalization of grammage units and recalculation of prices...

View source: R/f_data_processing.R

data_normR Documentation

Normalization of grammage units and recalculation of prices and quantities with respect to these units

Description

The function normalizes grammage units of products and recalculates product prices and quantities with respect to these normalized grammage units.

Usage

data_norm(
  data = data.frame(),
  rules = list(c("ml", "l", 1000), c("g", "kg", 1000)),
  all = TRUE
)

Arguments

data

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).

rules

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.

all

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.

Value

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.

Examples

# 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)))

PriceIndices documentation built on July 9, 2023, 6:20 p.m.