Suppose I have a list as
list1 = {1,2,3,4,5}
How could I create a table such that the first entry is the lagged entry of this list, i.e:
table1 = {{0,1},{1,2},{2,3},{3,4},{4,5}}
Thank you.
Mathematica Stack Exchange is a question and answer site for users of Wolfram Mathematica. It only takes a minute to sign up.
Sign up to join this communityYou can use the third and fourth arguments of Partition
:
Partition[list1, 2, 1, {-1, -1}, 0]
{{0, 1}, {1, 2}, {2, 3}, {3, 4}, {4, 5}}
Alternatively,
Transpose[{Most @ #, Rest @ #}] & @ Prepend[list1, 0]
{{0, 1}, {1, 2}, {2, 3}, {3, 4}, {4, 5}}
Partition[{0, 1, 2, 3, 4, 5}, 2, 1]
$\endgroup$