To calculate deciles in R, you can use the quantile() function with a sequence of probabilities for each decile. Deciles are a type of quantile that divide a dataset into ten equal parts.

In this article, we will explore how to calculate deciles in R using the quantile() function.

Method: Use quantile() Function

The quantile() function in R is used to calculate quantiles, including deciles. Here’s the syntax:

quantile(data, probs = seq(0.1, 0.9, by = 0.1))
  • data: The numeric vector for which you want to calculate deciles.
  • probs = seq(0.1, 0.9, by = 0.1): This generates a sequence of numbers from 0.1 to 0.9, incrementing by 0.1, representing the deciles.

The following example shows how to calculate deciles in R.

Use quantile() to Calculate Decile Values of a Vector

Let’s see how we can calculate decile values of a vector using the quantile() function in R:

# Create vector
data <- c(78, 89, 85, 84, 81, 79, 77, 85, 85, 81, 78, 89, 84, 84, 81, 80)

# Calculate decile values
deciles <- quantile(data, probs = seq(0.1, 0.9, by = 0.1))

# Display decile values
print(deciles)

Output: 👇️

 10%  20%  30%  40%  50%  60%  70%  80%  90% 
78.5 79.0 80.0 81.0 81.5 84.0 84.0 85.0 88.0 

In this example, the quantile() function calculates the decile values for the data vector. The output shows the values at each decile, dividing the dataset into ten equal parts.