问题
I can't seem to find an elegant solution to finding ranges. For me, it would come down to this:
> seq(1:10)
[1] 1 2 3 4 5 6 7 8 9 10
I would like to get the reverse:
function(c(1,2,3,4,5,6,7,8,9,10))
result 1:10
Real world problem is that I have 1200 indices, some are 0, some are 1:
c(0,0,0,0,0,0,1,1,1,1,1,1,0,0,0,0,1,0,0,1,1,1,1,1,1,0,0,0,0,1,1,1,1,1)
And I would like the ranges/coordinates within the vector for each set of 0s and 1s.
回答1:
Will this simple solution work?
> rev(seq(1:10))
[1] 10 9 8 7 6 5 4 3 2 1
> range(seq(1:10))
[1] 1 10
来源:https://stackoverflow.com/questions/48411151/r-range-of-number-sequences-or-how-can-i-get-the-reverse-of-110