1
$\begingroup$

This question already has an answer here:

I have this function

test=> Is just a list of lists of depth 4
list1={3,2,1,0}
list2={1,2,3,4}
lag[l_List, n_Integer] := Drop[PadLeft[l, Length[l] + n, "Blank"], -n]
lag[test[[1, #2]], #1]&/@list1/@list2

As you can see this does not work, I understand why it does not work, but I have not been able to come up with an solution. What I want to happen is described in the list below. Basically I want list1 to go into slot1 and list2 to go into slot2 stepwise as shown below.

lag[test[[1, 1]], 3]
lag[test[[1, 2]], 2]
lag[test[[1, 3]], 1]
lag[test[[1, 4]], 0]
$\endgroup$

marked as duplicate by Mr.Wizard Sep 18 '13 at 22:08

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 2
    $\begingroup$ Have you read the documentation on MapThread? $\endgroup$ – ssch Sep 18 '13 at 11:45
  • $\begingroup$ Yeah, Im struggling with the understanding how to assign different list to different slot $\endgroup$ – ALEXANDER Sep 18 '13 at 11:49
  • $\begingroup$ Related: (5217), (10211), (24939) $\endgroup$ – Mr.Wizard Sep 18 '13 at 22:08
5
$\begingroup$

Voting to close, but:

list1 = {3, 2, 1, 0};
list2 = {1, 2, 3, 4};
MapThread[lag[test[[1, #2]], #1] &, {list1, list2}]
$\endgroup$
  • $\begingroup$ aaaa, thought I came up with a good solution by myself, but yours is better. Would I be correct to state that MapThread is the same as using Map[apply[ ---> as I have done? $\endgroup$ – ALEXANDER Sep 18 '13 at 12:29
  • $\begingroup$ @ALEXANDER test this vb = Transpose[{list1, list2}]; Map[lag[test[[1, #[[2]]]], #[[1]]] &, vb]. In Mathematica you always have a lot of ways to do the same thing. $\endgroup$ – Dr. belisarius Sep 18 '13 at 12:42
1
$\begingroup$
list1 = {3, 2, 1, 0};
list2 = {1, 2, 3, 4};
vb = Transpose[{list1, list2}]
Map[(Apply[lag[test[[1, #2]], #1] &, #1]) &, vb]
$\endgroup$

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