How to Calculate Quantiles by Group in R?
In this article, we will discuss how to calculate quantiles by the group in R programming language.
To obtain the required quartiles, quantile() function is used.
quantile( data, probs)
- data: data whose percentiles are to be calculated
- probs: percentile value
To group data, we use dplyr module. This module contains a function called group_by() in which the column to be grouped by has to be passed.
To find quantiles of the grouped data we will call summarize method with quantiles() function.
summarize( function )
Example 1: Calculate Quantiles by group by summarizing one quartile with probability 0.5
Example 2: Calculate quantiles by group by summarizing three quartiles with probability 0.25, 0.5, and 0.75.