- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to extract the outliers of a boxplot in R?
To extract the outliers of a boxplot, we can use out function along with the boxplot function. For example, if we have a vector called X which contains some outliers then we can extract those outliers by using the command given below −
boxplot(df$X,plot=FALSE)$out
This command will not create a plot as plot is set to FALSE.
Example
Following snippet creates a sample data frame −
df=data.frame(x=rlnorm(25)) df
The following dataframe is created −
x 1 0.5699270 2 3.5812629 3 0.3507882 4 0.1400328 5 0.7239948 6 2.5494114 7 3.1243611 8 5.3207739 9 0.1672539 10 7.6235529 11 0.4950263 12 1.1713592 13 1.6590328 14 0.4404338 15 0.1354914 16 0.6192213 17 1.0878246 18 0.4084088 19 0.3980110 20 1.3915935 21 0.8679156 22 1.5447279 23 0.9476949 24 0.4036890 25 3.6822067
To create boxplot of x, add the following code to the above snippet −
df=data.frame(x=rlnorm(25)) boxplot(df$x)
Output
If you execute all the above given snippets as a single program, it generates the following output: −
To extract outliers from above boxplot, add the following code to the above snippet −
df=data.frame(x=rlnorm(25)) boxplot(df$x,plot=FALSE)$out
Output
If you execute all the above given snippets as a single program, it generates the following output: −
[1] 3.581263 5.320774 7.623553 3.682207
- Related Articles
- How to highlight outliers in a boxplot in R?
- How to hide outliers in base R boxplot?
- How to create a boxplot with outliers of larger size in R?
- How to change the color of outliers in base R boxplot?\n
- How to fill the outliers with different color in base R boxplot?
- How to display outliers in boxplot with different shape in base R?
- How to extract statistical summary from boxplot in R?
- How to remove outliers from multiple boxplots created with the help of boxplot function for columns of a data frame using single line code in R?
- How to create a horizontal boxplot in base R?
- How to create transparent boxplot in R?
- How to create boxplot of grouped data in R?
- How to create a boxplot with log of the variable in base R?
- How to show values in boxplot in R?
- How to change the color of box of boxplot in base R?
- How to create a rectangle inside boxplot in base R?

Advertisements