Identifies statistical outliers in a numeric variable using the Interquartile Range (IQR) method. Provides detailed diagnostics about the outlier detection process.
Value
If outliers are found:
Data frame containing rows with outlier values
Prints diagnostic information about quartiles and fences
If no outliers:
Returns NULL
Prints confirmation message
Details
The function uses the standard IQR method for outlier detection:
Calculates Q1 (25th percentile) and Q3 (75th percentile)
Computes IQR = Q3 - Q1
Defines outliers as values outside (Q1 - 1.5IQR, Q3 + 1.5IQR)
Diagnostic Output
Variable name
Q1 and Q3 values
IQR value
Upper and lower fence values
Number of outliers found
Examples
data(mtcars)
find_outliers(mtcars, mpg)
#> Variable name: mpg
#> Q1: 15.425 Q3: 22.8 IQR: 7.375
#> Upper fence: 33.8625 Lower fence: 4.3625
#> Number of outliers: 1
#> mpg cyl disp hp drat wt qsec vs am gear carb
#> Toyota Corolla 33.9 4 71.1 65 4.22 1.835 19.9 1 1 4 1
find_outliers(mtcars, wt, verbose = FALSE)
#> mpg cyl disp hp drat wt qsec vs am gear carb
#> Cadillac Fleetwood 10.4 8 472 205 2.93 5.250 17.98 0 0 3 4
#> Lincoln Continental 10.4 8 460 215 3.00 5.424 17.82 0 0 3 4
#> Chrysler Imperial 14.7 8 440 230 3.23 5.345 17.42 0 0 3 4