I have the following table:
User ID | Session ID | Time Stamp | Page |
---|---|---|---|
123 | 123.4 | HH:MM:01 | 1 |
123 | 123.4 | HH:MM:02 | 2 |
123 | 123.4 | HH:MM:05 | 3 |
123 | 123.4 | HH:MM:10 | 4 |
123 | 123.4 | HH:MM:11 | 5 |
122 | 1299.1 | HH:MM:01 | 2 |
122 | 1299.1 | HH:MM:02 | 3 |
128 | 124.4 | HH:MM:01 | 1 |
128 | 124.4 | HH:MM:02 | 2 |
And, I am trying to get a table like this:
User ID | Session ID | Time Stamp | Page | Next Page | Duration (secs) |
---|---|---|---|---|---|
123 | 123.4 | HH:MM:01 | 1 | 2 | 1 |
123 | 123.4 | HH:MM:02 | 2 | 3 | 3 |
123 | 123.4 | HH:MM:05 | 3 | 4 | 5 |
123 | 123.4 | HH:MM:10 | 4 | 5 | 1 |
122 | 1299.1 | HH:MM:01 | 2 | 3 | 1 |
128 | 124.4 | HH:MM:01 | 1 | 2 | 1 |
I know I have to use lead(), but I cannot figure out how to use the mutate and lead function together.
Any help is much appreciated. Thank you.