简体   繁体   中英

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.

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() .

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).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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