Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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]
share|improve this question

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  
Have you read the documentation on MapThread? –  ssch Sep 18 '13 at 11:45
    
Yeah, Im struggling with the understanding how to assign different list to different slot –  ALEXANDER Sep 18 '13 at 11:49
    
Related: (5217), (10211), (24939) –  Mr.Wizard Sep 18 '13 at 22:08

2 Answers 2

up vote 4 down vote accepted

Voting to close, but:

list1 = {3, 2, 1, 0};
list2 = {1, 2, 3, 4};
MapThread[lag[test[[1, #2]], #1] &, {list1, list2}]
share|improve this answer
    
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? –  ALEXANDER Sep 18 '13 at 12:29
    
@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. –  belisarius Sep 18 '13 at 12:42
list1 = {3, 2, 1, 0};
list2 = {1, 2, 3, 4};
vb = Transpose[{list1, list2}]
Map[(Apply[lag[test[[1, #2]], #1] &, #1]) &, vb]
share|improve this answer

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