title: R: Keep values below the 99 quantile for groups in data frame
body: <p>I have a dataframe with groups and values. Firstly, I calculate 99% quantile per group. Now, I want to remove the values above the 99% quantile for every group. </p>
  
  <pre><code>df&lt;-data.frame(group = rep(c("A", "B"), each = 4),
                 value = c(c(6,5,80,4,60)*10,3,5,4))
  
  # data
    group value
  1     A    60
  2     A    50
  3     A   800
  4     A    40
  5     B   600
  6     B     3
  7     B     5
  8     B     4
  </code></pre>
  
  <p>Calculate quantils for individual groups</p>
  
  <pre><code>quant&lt;-aggregate(df$value, by = list(df$group), FUN = quantile, probs  = 0.99)
  
  &gt; quant
    Group.1      x
  1       A 777.80
  2       B 582.15
  </code></pre>
  
  <p>I tried to apply the vector of quantiles to select lower values. However, it miss the group specification..  </p>
  
  <pre><code>df[df$value &lt; quant$x,]
  </code></pre>
  
  <p>Expected result:</p>
  
  <pre><code>  group value
  1     A    60
  2     A    50
  4     A    40
  5     B     3
  6     B     5
  7     B     4
  </code></pre>
  
  <p>How to apply vector of quantiles to keep only values below 99% by group in data frame?</p>