decision_modus: A function to get a decision (modus) from a vector of classes

View source: R/decision_modus.R

decision_modusR Documentation

A function to get a decision (modus) from a vector of classes

Description

decision_modus is a function that can be used to find the most frequent (modus) decision. The classes can be defined by the user (e.g., a", "n", "y" -> "ambiguous", "negative", "positive"). This function is useful if large collections of varying decision (e.g., "a", "a", "a", "n", "n") need to be condensed to a single decision (3 x "a", 2 x "n" -> "a").

Usage

decision_modus(data, variables = c("a", "n", "y"), max_freq = TRUE)

Arguments

data

is a table containing the classes.

variables

is the class to look for.

max_freq

is a logical parameter (default == TRUE) delivers either the most occurring class or a summary.

Value

gives a factor (S3 class, type of integer) as output for a decision

Author(s)

Stefan Roediger, Michal Burdukiewcz

Examples


# First example
# Enter a string of arbritary of "a","a","y","n"
# Result:
# [1] a
# Levels: a b n y

decision_modus(c("a","a","y","n","b"))

# Second example
# Analyze data from the decision_res_testdat.csv data file
filename <- system.file("decision_res_testdat.csv", package = "PCRedux")
my_data <- read.csv(filename)
head(my_data)

dec <- unlist(lapply(1L:nrow(my_data), function(i) {
       decision_modus(my_data[i, 2:4])
}))

names(dec) <- my_data[, 1]
dec


PCRedux documentation built on May 11, 2022, 5:18 p.m.