outliers_by_iqr | R Documentation |
Compute outliers for all columns of a numeric matrix using the IQR method. For each column of the input matrix, a value is called as an outlier if the value is less than the first quartile i.e. Q1 - IQR * scale factor or greater than Q3 + IQR * scale factor.
outliers_by_iqr(X, scale_factor = 1.5)
X |
numeric matrix or data.frame that can be converted to a numeric matrix with variables in the columns and sample names in the rows. |
scale_factor |
numeric. Factor to scale the outlier range. default 1.5. |
numeric matrix where values of 1L indicates an outlier and 0L indicates non-outlier
set.seed(12345)
M <- matrix(
data = c(rnorm(10, 10, 1), rnorm(10, 100, 15)),
ncol = 2,
dimnames = list(paste0("sample", 1:10), c("var1", "var2"))
)
# Create one outlier in first and last rows
M[1, 1] <- 100
M[1, 2] <- 1000
M[10, 1] <- -10
M[10, 2] <- 0
# Show outliers on boxplot
boxplot(M)
# Call outliers in each column
outliers_by_iqr(M)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.