DescTools (version 0.99.36)

CentralValue: Obtain statistic of centrality

Description

This function obtains a statistic of centrality of a variable given a sample of its values.

Usage

CentralValue(x, weights = NULL)

Arguments

x

a vector of values (the sample).

weights

a numerical vector of weights the same length as x giving the weights to use for elements of x.

Value

A number if the variable is numeric. A string with the name of the most frequent nominal value, otherwise.

Details

If the variable is numeric it returns the median of the given sample, if it is a factor it returns the mode. In other cases it tries to convert to a factor and then returns the mode.

References

Torgo, L. (2010) Data Mining using R: learning with case studies, CRC Press (ISBN: 9781439810187).

http://www.dcc.fc.up.pt/~ltorgo/DataMiningWithR

See Also

mean, median

Examples

Run this code
# NOT RUN {
# An example with numerical data
x <- rnorm(100)
CentralValue(x)

# An example with nominal data
y <- factor(sample(1:10, 200, replace=TRUE), levels=1:10, 
            labels=paste('v', 1:10, sep=''))
CentralValue(y)
# }

Run the code above in your browser using DataLab