【问题标题】:Subset dataset to 99.5th percentile for each of a categorical variable对于每个分类变量,将数据集子集到第 99.5 个百分位数
【发布时间】:2018-01-01 02:28:12
【问题描述】:

我想对 data.frame 进行子集化,以仅保留每个分类变量的第 99.5 个百分位数。

我的数据已使用分钟 = 分钟 并且位置=位置

我想取出每个位置前 0.5% 的分钟数据。

新子集将具有位置 1 的 99.5%。位置 2 的 99.5%,等等。

谢谢!

【问题讨论】:

  • 欢迎来到 Stack Overflow!您似乎在要求某人为您编写一些代码。 Stack Overflow 是一个问答网站,而不是代码编写服务。请see here学习如何写出有效的问题。

标签: r subset categorical-data quantile


【解决方案1】:

这可能会解决您的问题,尽管如果您可以发布您的数据会非常有帮助。

library(plyr)

#add a column with information on where the 99.5% cutoff is
new.dataset1 <- ddply(your.dataset, "location", mutate, minutes.99.5.cutoff =                         
                      quantile(minutes.used, 0.95)) 

#subset the data to only include the bottom 99.5% of the data, then only 
#select the first two columns
trimmed.dataset <- new.dataset1[which(new.dataset1$minutes.used <= 
                                      new.dataset1$minutes.99.5.cutoff),1:2]

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-09-27
    • 2015-07-16
    • 2016-05-25
    • 1970-01-01
    • 2011-09-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多