开发者

How do i create ranges dynamically in R? [duplicate]

This question already has answers here: Closed 11 years ago.

Possible Duplicate:

Create categorical variable in R based on range

Given a range and number of intervals that are desired how do i create equal intervals in R. eg. If the range is between 1 and 100 and i want to create 10 intervals, I should get 1 - 10, 11 - 20, ..., 91 - 100. Only this function should work for any range and any number of intervals. I开发者_如何转开发f i have a range of 0 to 1 and number of intervals 30, then it should create the ranges such as 0 - 0.03, ..., 0.97 - 1, and so on. The aim is to use these ranges to obtain values from a data.frame.


If you have

minVal<-0
maxVal<-1
numItv<-30

you can use

seq(minVal, maxVal, length.out=numItv+1)

to get the cutpoints for your intervals.


See ?cut. For your initial question:

cut(x,breaks=(0:10)*10)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜