Reputation: 167
I want to create intervals in R, I already got some code to get specific numbers.
For example the following:
"33" "45" "77" "82" "85"
As the result I want to get the following, the most important is to get the ranges, it doesnt have to look like this exactly:
c(0,33), c(34,45), c(46,77), c(78,82), c(83,85), c(86,100)
How can I achieve this for any given example of numbers? 0 should always be the minimum and 100 always the max.
I have tried something like this, but obviously this can't work because k is not defined:
for(number in numbers) {
interval = c(number[k] +1, number[k+1])
Upvotes: 0
Views: 426
Reputation: 10375
In a matrix
x=c(33,45,77,82,85)
cbind(
c(0,x+1),
c(x,100)
)
[,1] [,2]
[1,] 0 33
[2,] 34 45
[3,] 46 77
[4,] 78 82
[5,] 83 85
[6,] 86 100
Upvotes: 2