To calculate the five number summary in R, you can use the fivenum()
function. This function provides the minimum, maximum, median, first quartile (Q1), and third quartile (Q3) values of a dataset.
In this article, we will explore how to calculate the five number summary in R using the fivenum()
function with examples.
Method: Use fivenum() Function
The fivenum()
function in R is used to calculate the five number summary. Here’s the syntax:
fivenum(data)
The following example shows how to use the fivenum()
function in R.
Use fivenum() to Calculate Five Number Summary
Let’s see how we can calculate the five number summary of a data frame:
# Create data frame
df <- data.frame(Machine_name=c("A","B","C","D","E","F","G","H"),
Pressure=c(78.2, 78.2, 71.7, 80.21, 80.21, 82.56, 72.12, 73.85),
Temperature=c(35, 36, 36, 38, 32, 32, 31, 34))
# Calculate five number summary of data frame
d <- fivenum(df$Temperature)
# Print five number summary of data frame
print(d)
Output: 👇️
[1] 31.0 32.0 34.5 36.0 38.0
In this example, the fivenum()
function calculates the five number summary for the Temperature
column of the data frame.
The output includes the minimum, first quartile (Q1), median, third quartile (Q3), and maximum values for the [Temperature
] column.
The output shows minimum value is 31.0, Q1 is 32.0, the median is 34.5, Q3 is 36.0, and the maximum value is 38.0.