有一个排序整数向量,我想从每个极端提取10 %的数据。例如,整数从1到100,我想从数据的左尾取10 % (1: 10 ),从数据的右尾取10% (91:100)。我可以先对数据进行排序,然后再将其划分为100,然后提取第一部分和最后一部分。但是,我想知道R是否为它建立了一个函数。
谢谢!
发布于 2014-06-15 17:38:03
仔细使用quantile和sample如何?
xx <- rnorm(1e3)
thresh <- quantile(xx, c(.1, .9))
left <- xx[xx <= thresh[[1]]]
left <- sample(left, length(left) %/% 10)
right <- xx[xx >= thresh[[2]]]
right <- sample(right, length(right) %/% 10)https://stackoverflow.com/questions/24232245
复制相似问题