2

I am trying to apply the quantile function to a column (y) of my data (tab) considering the groups (column x):

z <- with (tab, tapply (y, x, quantile))

tab
      x y
1 1 0.11
2 1 0.07
3 0.04
4 2 0.39
5 2 0.12
6 3 0.21
7 3 0.06
8 3 0.00
9 3 0.12
10 3 0.36
11 4 0.08
12 4 0.15
13 4 0.09
14 4 0.30
15 4 0.12
16 4 0.13
17 4 0.07

My question: how to get only the 90% percentile? (not all quantiles 0% 25% 50% 75% 100%)

Ph.D.Student
  • 704
  • 6
  • 27

1 Answers1

4

Add an additional argument p=0.9:

tapply(tab$y, tab$x, quantile, p=0.9)
Karolis Koncevičius
  • 9,417
  • 9
  • 56
  • 89