对两个百分比(R)之间的范围进行子集化

时间:2016-05-10 17:57:09

标签: r range subset percentage

我有一个数字向量,包含从-217544到319842的150个观察值。 我想基于一系列百分比创建一个子集。换句话说,我想把所有东西都在30%到70%之间。

例如:

bm.sort <- c(1, 2, 3, 4, 5, 6, 7, 8, 9 ,10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20)

我想让代码选择中间40%(7到14)。

我到目前为止已尝试过代码

bm.m <- subset(bm.sort, bm.sort >= quantile(bm.sort, 0.3 %between% bm.sort <= quantile(bm.sort, 0.7)))

bm.m <- subset(bm.sort, bm.sort >= quantile(bm.sort, 0.3 | bm.sort <= quantile(bm.sort, 0.7)))

然而,当我使用这段代码时,我只收到一个观察,而不是我应该收到的60个观察范围。

任何帮助都将不胜感激。

1 个答案:

答案 0 :(得分:0)

我设法弄明白了(缺少&#34;)&#34; ),抱歉不必要地占用你的时间。

感谢您的帮助。

相关问题