Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

range

r

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

like image 874
Sam Avatar asked Dec 04 '22 22:12

Sam


1 Answers

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.

like image 148
Nick Sabbe Avatar answered Dec 08 '22 16:12

Nick Sabbe