【发布时间】:2016-01-28 11:33:20
【问题描述】:
我想比较 9 种分位数。
我计算了 data.frame 中变量 a 的分位数。对于每种类型 (1-9),我计算了 10 个分位数(其中 1 为最高的 10%,10 为最低的 10%)。
set.seed(123)
library(dplyr)
a <- as.numeric(sample(1.1e6:87e6, 366, replace=T))
b <- runif(366, 0.005, 2.3)
df<- data.frame(a,b)
df <- df %>%
mutate(type1 = 11 - as.integer(cut(a, quantile(a, probs=0:10/10, type = 1), include.lowest=TRUE)),
type2 = 11 - as.integer(cut(a, quantile(a, probs=0:10/10, type = 2), include.lowest=TRUE)),
type3 = 11 - as.integer(cut(a, quantile(a, probs=0:10/10, type = 3), include.lowest=TRUE)),
type4 = 11 - as.integer(cut(a, quantile(a, probs=0:10/10, type = 4), include.lowest=TRUE)),
type5 = 11 - as.integer(cut(a, quantile(a, probs=0:10/10, type = 5), include.lowest=TRUE)),
type6 = 11 - as.integer(cut(a, quantile(a, probs=0:10/10, type = 6), include.lowest=TRUE)),
type7 = 11 - as.integer(cut(a, quantile(a, probs=0:10/10, type = 7), include.lowest=TRUE)),
type8 = 11 - as.integer(cut(a, quantile(a, probs=0:10/10, type = 8), include.lowest=TRUE)),
type9 = 11 - as.integer(cut(a, quantile(a, probs=0:10/10, type = 9), include.lowest=TRUE)))
我想计算 9 种类型的第 10 个分位数中的 a 的平均值。我应该有 a 的 90 个平均值。
我该怎么做?
【问题讨论】:
-
你的分位数都是一样的。我假设您正在寻找类似
df %>% group_by(type1) %>% summarise_each(funs(mean))? -
你为什么不只看分位数?
-
@42- 因为我的分析涉及获取每个分位数的均值并将其乘以另一个参数。