Learn R Programming

DEXiR (version 1.0.2)

convert_data_discrete: convert_data_discrete

Description

#' A helper function for converting individual columns of alternatives' data. It is assumed that data contains data corresponding to a discrete DexiAttribute. During conversion, data elements are converted either to sets or distributions, and function aggregate if applied on them. When interpret = "set", values are also optionally converted to the interval [omin:omax], and reversed using reverse_value() for scales whose $order = "descending".

Usage

convert_data_discrete(
  data,
  scale,
  interpret = c("set", "distribution", "none"),
  aggregate = min,
  omin = 0,
  omax = 1,
  map_values = TRUE,
  reverse_descending = TRUE
)

Value

Vector of converted values.

Arguments

data

A vector containing DEXi values: single numbers, integer vectors or distribuions. Typically a data.frame column of DEXi alternatives' data.

scale

A DexiDiscreteScale object or a discrete DexiAttribute object.

interpret

Either "set" (default), "distribution" or "none". Determines how are individual data elements interpreted: as sets or distributions. Actually, each element is converted either to a set or distribution prior do applying aggregate(). When interpret = "none", just aggregate() is applied on the original value from data, without any value scaling or reversal.

aggregate

A function applied on each interpreted data element. Normally a function that maps a numeric vector (set or distribution) to a single number. Default: min().

omin

Lower output bound for lin_map() value scaling. Applies only when interpret = "set".

omax

Upper output bound for lin_map() value scaling Applies only when interpret = "set".

map_values

logical(1). Whether or not to perform value scaling using lin_map(). Applies only when interpret = "set".

reverse_descending

logical(1). Whether or not to reverse values of a "descending" scale.

See Also

lin_map(), reverse_value()

Examples

Run this code
scla <- DexiDiscreteScale(values = c("L", "M", "H"))
scld <- DexiDiscreteScale(values = c("L", "M", "H"), order = "descending")
convert_data_discrete(c(1, 2, 3), scla)    # 0.0 0.5 1.0
convert_data_discrete(c(1, 2, 3), scld)    # 1.0 0.5 0.0
convert_data_discrete(list(1, 2, 3), scla) # 0.0 0.5 1.0
convert_data_discrete(list(1, 2, 3), scld) # 1.0 0.5 0.0
convert_data_discrete(list(1, 2, 3), scld, omax=10) # 10  5  0
data <- list(1, c(1,2), distribution(0.2, 0, 0.8), NA)
convert_data_discrete(data, scla, omax=10) #  0  0  0 NA
convert_data_discrete(data, scld, omax=10) # 10 10 10 NA
convert_data_discrete(data, scla, aggregate=max, omax=10)  #  0  5 10 NA
convert_data_discrete(data, scla, aggregate=mean, omax=10) # 0.0 2.5 5.0  NA

Run the code above in your browser using DataLab