Learn R Programming

StatMeasures (version 1.0)

outliers: Identify outliers in a variable

Description

Takes in a vector, and returns count and index of outliers

Usage

outliers(vector)

Arguments

vector
an integer or numeric vector

Value

a list with two elements: count and index of outliers

Details

The function uses the same criteria to identify outliers as the one used for box plots. All values that are greater than 75th percentile value + 1.5 times the inter quartile range or lesser than 25th percentile value - 1.5 times the inter quartile range, are tagged as outliers.

The individual elements (number of outliers and index of outliers) of the two element output list can be picked using the code given in example. The index of outliers can be used to get a vector of all outliers.

See Also

decile, pentile, imputemiss

Examples

Run this code
# Scores vector
scores <- c(1, 4, 7, 10, 566, 21, 25, 27, 32, 35,
            49, 60, 75, 23, 45, 86, 26, 38, 34, 223, -3)

# Identify the count of outliers and their index
ltOutliers <- outliers(vector = scores)
numOutliers <- ltOutliers$numOutliers
idxOutliers <- ltOutliers$idxOutliers
valOutliers <- scores[idxOutliers]

Run the code above in your browser using DataLab