Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 201839

Recursion that splits a object with numbers in several data frame rows

$
0
0

I want to write a function that splits a vector with several numbers in a way which if I have the line:

secs = c(1, 5, 8, 19, 25, 91)

It'll answer me a data frame with two rows, called st and end in which each line I would have a value and the next one in the vector minus 1. For example, if I use apply(secs, function), R would answer me the following:

|  st | end|
|  1  |  4 |
|  5  |  7 |
|  8  | 18 |
| 19  | 24 |
| 25  | 91 | 

Note that the last value, i.e. 91 remains the same, I want that to remain the same value because its the last value. I tried to do that function via recursion, but failed to do so.


Viewing all articles
Browse latest Browse all 201839

Trending Articles