Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in R Programming by (50.2k points)

Basically I have plotted a boxplot for PM2.5 levels per year.

Boxplot(PM2.5~year, data=subset(dat, hour==12), las=1)

But I want to know how to extract values like the median from the boxplots?

1 Answer

0 votes
by (107k points)

In R programming, the boxplot function from ggplot2 package also returns the summary, you just have to assign it to a variable:

res <- boxplot(Sepal.Length ~ Species, data=iris)

Within the res variable there exists an element stats:

> res$stats

     [,1] [,2] [,3]

[1,]  4.3  4.9  5.6

[2,]  4.8  5.6  6.2

[3,]  5.0  5.9  6.5

[4,]  5.2  6.3  6.9

[5,]  5.8  7.0  7.9

These are quartile summaries of the boxes. The median is the middle one, so:

> res$stats[3,]

[1] 5.0 5.9 6.5

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...