Re: Joining List of Lists
- To: mathgroup at smc.vnet.net
- Subject: [mg64388] Re: Joining List of Lists
- From: "Jens-Peer Kuska" <kuska at informatik.uni-leipzig.de>
- Date: Wed, 15 Feb 2006 03:32:01 -0500 (EST)
- Organization: Uni Leipzig
- References: <dsrtn1$58h$1@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
Hi,
extend the shorter of the list by {{},{},{},..}
so that both list have equal length and use
MapThread[Join,{lst1,list2}]
Regards
Jens
"Benedetto Bongiorno" <bbongiorno at attglobal.net>
schrieb im Newsbeitrag
news:dsrtn1$58h$1 at smc.vnet.net...
| To All,
|
| In the folowing routine, I am trying to combine
two tables of lists of
| lists, that are not of equal size, by
| the intersection index of a common column of
both tables.
| The routine works but it runs for hours. The
bottleneck is the join
| routine using For.
| How can I use Map or MapThread to speed up the
process?
|
| Thank you.
|
| Ben Bongiorno
|
|
| "Create Index"
| "Create an Index of equivalents"
|
| Dimensions[idx]
| {175371,4}
|
| Dimensions[data]
| {314791,13}
|
| aa = idx[[All,loc02[[1]]]];
| bb = data[[All,loc01[[5]]]];
| indx = Intersection[aa,bb];
|
| Dimensions[indx]
| {16267}
|
| "Select the rows with matching field"
|
| ans01 = Select[idx, MemberQ[indx,
#[[loc02[[1]]]]]&];
| ans02 = Select[data,
MemberQ[indx,#[[loc01[[5]]]]]&];
|
| Dimensions[ans01]
| {16267,4}
|
| Dimensions[ans02]
| {314791,13}
|
| "Join "
|
| descripData={};
|
| n=Length[ans02]+1;
|
| For[i=1,i<n,i++,
| nn=Length[ans01]+1;
| For[j=1,j<nn,j++,
|
If[ans02[[i,loc01[[5]]]]==ans01[[j,loc02[[1]]]],
|
AppendTo[descripData,RowJoin[{ans02[[i]]},{ans01[[j]]}]]]]];
|
| Dimensions[descripData]
| {314791,1,17}
|
| descripData=Flatten[descripData,1];
| Dimensions[descripData]
| {314791,17}
|