简体   繁体   中英

R : Percentile 90% with tapply

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%)

添加一个附加参数p=0.9

tapply(tab$y, tab$x, quantile, p=0.9)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM