title: Calculate the quantile of multiple Groups in same Dataframe in R
body: <p>I have a dataframe in R with the following format :</p>
  <pre><code>ClientID     Group   CountC   
    X1           A       3
    R3           B       2
    D4           A       1
    T5           A       7
    H0           B       5 
  </code></pre>
  <p>I want to calculate the quartiles of <code>CountC</code> and store the values in another dataframe, I did the following code:</p>
  <pre><code>calculate_quantile &lt;- function(data, proba) { 
    z &lt;- quantile(data, proba)
    df &lt;- data.frame(Proba = proba, Value = z)
    return(df)
  }
  
  proba = c(0.25, 0.50, 0.75)
  
  quartileDF &lt;- calculate_quantile(df$CountC, proba)
  </code></pre>
  <p>Result in <code>quartileDF</code> is in the following format:</p>
  <pre><code>        Proba    Value
  25%      0.25      1
  50%      0.50      2
  75%      0.75      7 
  </code></pre>
  <p>What I need to do now is calculate the same thing but <strong>by group</strong>.</p>
  <p>I tried the following function:</p>
  <pre><code>q = c(.25, .5, .75)
  
  quartileDFbyGroup &lt;- 
    df%&gt;%
      group_by(Group) %&gt;%
        summarize(quant25 = quantile(df$CountC, probs = q[1]), 
                quant50 = quantile(df$CountC, probs = q[2]),
                quant75 = quantile(df$CountC, probs = q[3]))
  </code></pre>
  <p>But it gives me the <strong>same values</strong> for both groups:</p>
  <pre><code>Group     quant25  quant50   quant75
    A         1         2        7
    B         1         2        7
  </code></pre>
  <p>I tried to do it manually and in the tedious way, to be sure:</p>
  <pre><code>df_A = df[df['Group']=='A',]
  df_B = df[df['Group']=='B',]
  proba = c(0.25, 0.50, 0.75)
      
  quartileDF_A &lt;- calculate_quantile(df_A$CountC, proba)
  quartileDF_B &lt;- calculate_quantile(df_B$CountC, proba)
  </code></pre>
  <p>The values I get in each Group dataframe are not the same.</p>
  <p>Not sure what I am doing wrong.</p>
  <p>Can you help me calculate the quantile dynamically of 2 groups in the same dataframe?</p>