简体   繁体   English

如何获取ntile()的间隔

[英]How to get the intervals for ntile()

I was trying to figure out if there is a way to get the intervals used for when ntile() is used. 我试图找出是否有一种方法来获取使用ntile()时的间隔。

I have a sample that I want to use as a basis for getting the percentile values of a larger sample, and I was hoping to find a way to get the value of the intervals for when I use ntile() . 我有一个样本,希望以此为基础来获取较大样本的百分位值,并且我希望找到一种方法来获取使用ntile()时的间隔值。

Any enlightenment on this would be appreciated. 对此有任何启示。

I really want to put this as a comment, but I stil can't comment. 我真的很想对此发表评论,但我无法发表评论。

How about using quantile to generate the interval, like this: 如何使用分位数来生成间隔,如下所示:

# create fake data; 100 samples randomly picked from 1 to 500
fakeData <- runif(100, 1, 500)

# create percentile values; tweak the probs to specify the quantile that you want
x <- quantile(fakeData, probs = seq(0, 1, length.out = 100))

Then you can apply that interval to the larger data set (ie, using cut, which might give the same result to the ntile of dplyr). 然后,您可以将该时间间隔应用于较大的数据集(即,使用cut可能会使dplyr的ntile产生相同的结果)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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