Re: Joining List of Lists
- To: mathgroup at smc.vnet.net
- Subject: [mg64402] Re: Joining List of Lists
- From: "Valeri Astanoff" <astanoff at yahoo.fr>
- Date: Thu, 16 Feb 2006 03:05:09 -0500 (EST)
- References: <dsrtn1$58h$1@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
Why not something non-procedural like this: In[1]:= listJoin[dataRow_List, loc1_Integer, loc2_Integer]:= If[(sel=Select[idx,dataRow[[loc1]] == #[[loc2]]&]) == {}, dataRow, Join[dataRow,First@sel]] Example (idx index in position 2 and data index in 5): In[2]:= idx={{1,1,1,1},{1,2,1,1},{1,3,1,1},{1,4,1,1},{1,5,1,1}}; In[3]:= data= {{1,1,1,1,0,1,1,1,1,1,1,1,1}, {2,1,1,1,2,1,1,1,1,1,1,1,1}, {3,1,1,1,3,1,1,1,1,1,1,1,1}, {4,1,1,1,4,1,1,1,1,1,1,1,1}, {5,1,1,1,6,1,1,1,1,1,1,1,1}}; In[4]:= descripData = listJoin[#,5,2]& /@ data Out[4]= {{1,1,1,1,0,1,1,1,1,1,1,1,1}, {2,1,1,1,2,1,1,1,1,1,1,1,1,1,2,1,1}, {3,1,1,1,3,1,1,1,1,1,1,1,1,1,3,1,1}, {4,1,1,1,4,1,1,1,1,1,1,1,1,1,4,1,1}, {5,1,1,1,6,1,1,1,1,1,1,1,1}} hth v.a.