rank_topsis <- function(df, weights_topsis) { alternatives <- df[3:nrow(df), 1] alternatives <- as.data.frame(alternatives) colnames(alternatives) <- "Alternatives" weights_decisor <- as.numeric(df[2, 2:ncol(df)]) criteria_direction <- df[1, 2:ncol(df)] criterias <- colnames(df)[2:ncol(df)] matrix_decis <- as.data.frame(df[3:nrow(df), 2:ncol(df)]) colnames(matrix_decis) <- criterias matrix_decis <- matrix_decis %>% mutate_all(as.numeric) criteria_direction <- ifelse(criteria_direction == "MAX", "+", ifelse(criteria_direction == "MIN", "-", criteria_direction)) criteria_direction <- as.character(criteria_direction) object_topsis <- topsis(as.matrix(matrix_decis), weights_topsis, criteria_direction) rank_TOPSIS <- matrix_decis rank_TOPSIS$TOPSIS <- object_topsis$score rank_TOPSIS <- rank_TOPSIS %>% mutate(Alternatives = alternatives) %>% select(Alternatives, everything()) %>% arrange(desc(TOPSIS)) %>% mutate(Position = row_number()) %>% select(Alternatives, Position, everything()) colnames(rank_TOPSIS[,1]) <- "Alternatives" return(rank_TOPSIS) }