IQR and boxplot
To better visualise your data's quartiles you can create a boxplot using the function boxplot()
(in the same way as you used hist()
and barplot()
).
Similarly, you can calculate the interquartile range manually by subtracting the value of the third quartile from the value of the first quartile, or we can use the function IQR()
on your variable of interest. Let's try out making a boxplot and calculating the interquartile range of the mtcars
variable qsec
.
This exercise is part of the course
Basic Statistics
Exercise instructions
- Use the
boxplot()
function on the variableqsec
ofmtcars
- Calculate the interquartile range of
qsec
frommtcars
usingIQR()
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Make a boxplot of qsec
# Calculate the interquartile range of qsec