0
$\begingroup$

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.

$\endgroup$
  • 1
    $\begingroup$ Partition[{0, 1, 2, 3, 4, 5}, 2, 1] $\endgroup$ – user6014 Aug 27 at 21:23
2
$\begingroup$

You 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}}

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.