I know there are a lot of posts about how to repeat rows making the whole "repeated" rows following the "whole" original data. However, my question is a bit different, what I want is to repeat each row and let the newly created row becoming the next row of the repeated rows, meanwhile, I would like to create a new variable for each row.
To make my example clear, you can use this example data frame:
data.frame(a = c(1,2,3),b = c(1,2,3))
a b
1 1 1
2 2 2
3 3 3
What I want to get is some data frame like this:
a b type
1 1 1 origin
2 1 1 destination
3 2 2 origin
4 2 2 destination
5 3 3 origin
6 3 3 destination
Any hint will be much appreciated! Thanks for your help in advance