Defines functions weightedSum

Documented in weightedSum

weightedSum <- function(performanceTable, criteriaWeights, alternativesIDs = NULL, criteriaIDs = NULL){
  ## check the input data
  if (!((is.matrix(performanceTable) || (is.data.frame(performanceTable))))) 
    stop("wrong performance table, should be a matrix or a data frame")
  if (!(is.vector(criteriaWeights)))
    stop("criteria weights should be a vector")
  if (!(is.null(alternativesIDs) || is.vector(alternativesIDs)))
    stop("alternatives IDs should be in a vector")
  if (!(is.null(criteriaIDs) || is.vector(criteriaIDs)))
    stop("criteria IDs should be in a vector")
  ## filter the performance table and the criteria according to the given alternatives and criteria
  if (!is.null(alternativesIDs)) performanceTable <- performanceTable[alternativesIDs,]
  if (!is.null(criteriaIDs)) performanceTable <- performanceTable[,criteriaIDs]
  if (!is.null(criteriaIDs)) criteriaWeights <- criteriaWeights[criteriaIDs]
  ## transform performanceTable to matrix
  ## now calculate the weighted sum
  for (i in 1:dim(performanceTable)[1]){
    out<-rbind(out, crossprod(performanceTable[i,],criteriaWeights))
  names(out) <- rownames(performanceTable)

Try the MCDA package in your browser

Any scripts or data that you put into this service are public.

MCDA documentation built on March 18, 2018, 1:59 p.m.