centralValue: Obtain statistic of centrality

Description Usage Arguments Details Value Author(s) References See Also Examples

View source: R/utils.R

Description

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

Usage

1
centralValue(x, ws = NULL)

Arguments

x

A vector of values (the sample).

ws

A vector of case weights (defaulting to NULL, i.e. no case weights).

Details

If the variable is numeric it returns de 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.

Value

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

Author(s)

Luis Torgo ltorgo@dcc.fc.up.pt

References

Torgo, L. (2016) Data Mining using R: learning with case studies, second edition, Chapman & Hall/CRC (ISBN-13: 978-1482234893).

http://ltorgo.github.io/DMwR2

See Also

mean, median

Examples

1
2
3
4
5
6
7
# 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)

DMwR2 documentation built on May 2, 2019, 1:42 p.m.