Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #10615 > unrolled thread

Combining Two Lists

Started byHershel Lackey <hhl089827@gmail.com>
First post2012-06-24 08:26 +0000
Last post2012-06-26 08:46 +0000
Articles 2 — 2 participants

Back to article view | Back to comp.soft-sys.math.mathematica


Contents

  Combining Two Lists Hershel Lackey <hhl089827@gmail.com> - 2012-06-24 08:26 +0000
    Re: Combining Two Lists nanobio9 <kuokan.liang@gmail.com> - 2012-06-26 08:46 +0000

#10615 — Combining Two Lists

FromHershel Lackey <hhl089827@gmail.com>
Date2012-06-24 08:26 +0000
SubjectCombining Two Lists
Message-ID<js6j0e$87r$1@smc.vnet.net>
Hi,

I'm having a little difficulty in combining two lists.  These lists
contain individual sets of data and then particular items within the
set.  On one list the first column is the set the data is in and the
second column is the particular item, and this is followed by 5
properties of that item.  The second list starts the same, where the
first column is the set the data is in and the second column is the
item, but instead of having the properties listed out in individual
columns the data set repeats itself listing the properties A,B,C,D,E,F
all in the same column.   Below is a representative example of the two
list.

List 1
Data Set	Item #	Property 1	Property 2	Property 3	Property 4	Property 5
Q1	           1	            6.78	     25.61	   30.90	  48.90	 0.61
Q1	           2	           12.57	    23.44	    5.22	  37.20	6.90
Q2	           8	          18.78	  21.17	11.37  	2.54	        0.82
Q2	           2	          34.81	14.87	15.04	36.78	4.54
Q2	          10     	22.75	10.34	16.61	23.49	3.86
Q3	           5	         47.15	7.23	        11.23	        40.01	3.53
Q3	          8	        28.71	12.41	18.40	49.17	5.99

List 2

Data Set	Item#	Property 6	Measure %
Q1	          1	              A	     0
Q1	          1	              B	     5
Q1	          1	              C	    15
Q1	          1	              D	    80
Q1	          1	              E	     0
Q1	          1	              F	     0
Q1	          2	              A	    80
Q1	          2	              B	    10
Q1	          2	              C	    10
Q1	          2	              D	     0
Q1	          2	              E	     0
Q1	          2	              F	     0
Q2	          2		      A	     5
Q2	          2		      B	     5
Q2	          2		      C	     0
Q2	          2		      D	     15
Q2	          2		      E	     0
Q2		  2		      F	     0
Q2		  8		      A	     0
Q2		  8		      B	     0
Q2		  8		      C	     65
Q2		  8		      D	     15
Q2		  8		      E	     0
Q2		  8		      F	     20
Q2		  10		      A	     5
Q2		  10		      B	     5
Q2		  10		      C	     85
Q2		  10		      D	     0
Q2		  10		      E	     0
Q2		  10		      F	     0
Q3		  5		      A	     8
Q3		  5		      B	     0
Q3		  5		      C	     85
Q3		  5		      D	     7
Q3		  5		      E	     0
Q3		  5		      F	     0
Q3		  8		      A	     12
Q3		  8		     B		     3
Q3		  8		     C		     60
Q3		  8		     D		     15
Q3		  8		     E		     0
Q3		  8		     F		     0

Note that the item # are repeat between different data sets, and data
sets are different sizes.

What I would like to do is combine the two lists matching the first
two columns, to give groups like {Q1, 1, 6.7, 25.61, 30.90, 48.90,
0.61,{0,5,15,80,0,0}} for each individual.  I have used Cases to
identify matching data sets and item numbers in the two lists.  It is
then possible to append the two portions of the list to give part of
the desired data set.  However, this was laborious in typing in every
data set and then item # into Cases, and impractical for large data
sets.  I'm sure there is a way to Map Cases or Select over the list,
and append the appropriate data when data set and item # match, but I
haven't figured out how to do that.  Also it seems possible to use an
if then statement; that if the data set and item # match then append,
else move through the list.  However, I haven't figured out how to
code for this either.  I appreciate any help.

Thanks,

Hershel

[toc] | [next] | [standalone]


#10630

Fromnanobio9 <kuokan.liang@gmail.com>
Date2012-06-26 08:46 +0000
Message-ID<jsbsts$6mn$1@smc.vnet.net>
In reply to#10615
Hi,

I have no idea of how much more programming will be 'little' enough
for you. My penny is, for example for the second list (let's suppose
that it is called list2), you can group the data concerning a specific
item in a specific quarter simply by doing:

groupedList = Gather[ list2, #1[[ {1,2} ]] == #2[[ {1,2} ]] ];

Then in 'groupedList', each element (level 1) contains data pertaining
to a specific item in a specific quarter. The same should work for the
first list, too. Then it is up to you how you would like to join your
data. (property names can be compared later, too)

Best,
KKL

> Hi,
>
> I'm having a little difficulty in combining two lists.  These lists
> contain individual sets of data and then particular items within the
> set.  On one list the first column is the set the data is in and the
> second column is the particular item, and this is followed by 5
> properties of that item.  The second list starts the same, where the
> first column is the set the data is in and the second column is the
> item, but instead of having the properties listed out in individual
> columns the data set repeats itself listing the properties A,B,C,D,E,F
> all in the same column.   Below is a representative example of the two
> list.
>
> List 1
> Data Set        Item #  Property 1      Property 2      Property 3      Property 4      Property 5
> Q1                 1                6.78             25.61         30.90          48.90  0.61
> Q1                 2               12.57            23.44           5.22          37.20 6.90
> Q2                 8              18.78   21.17 11.37   2.54            0.82
> Q2                 2              34.81 14.87   15.04   36.78   4.54
> Q2                10            22.75   10.34   16.61   23.49   3.86
> Q3                 5             47.15  7.23            11.23           40.01   3.53
> Q3                8             28.71   12.41   18.40   49.17   5.99
>
> List 2
>
> Data Set        Item#   Property 6      Measure %
> Q1                1                   A      0
> Q1                1                   B      5
> Q1                1                   C     15
> Q1                1                   D     80
> Q1                1                   E      0
> Q1                1                   F      0
> Q1                2                   A     80
> Q1                2                   B     10
> Q1                2                   C     10
> Q1                2                   D      0
> Q1                2                   E      0
> Q1                2                   F      0
> Q2                2                   A      5
> Q2                2                   B      5
> Q2                2                   C      0
> Q2                2                   D      15
> Q2                2                   E      0
> Q2                2                   F      0
> Q2                8                   A      0
> Q2                8                   B      0
> Q2                8                   C      65
> Q2                8                   D      15
> Q2                8                   E      0
> Q2                8                   F      20
> Q2                10                  A      5
> Q2                10                  B      5
> Q2                10                  C      85
> Q2                10                  D      0
> Q2                10                  E      0
> Q2                10                  F      0
> Q3                5                   A      8
> Q3                5                   B      0
> Q3                5                   C      85
> Q3                5                   D      7
> Q3                5                   E      0
> Q3                5                   F      0
> Q3                8                   A      12
> Q3                8                  B               3
> Q3                8                  C               60
> Q3                8                  D               15
> Q3                8                  E               0
> Q3                8                  F               0
>
> Note that the item # are repeat between different data sets, and data
> sets are different sizes.
>
> What I would like to do is combine the two lists matching the first
> two columns, to give groups like {Q1, 1, 6.7, 25.61, 30.90, 48.90,
> 0.61,{0,5,15,80,0,0}} for each individual.  I have used Cases to
> identify matching data sets and item numbers in the two lists.  It is
> then possible to append the two portions of the list to give part of
> the desired data set.  However, this was laborious in typing in every
> data set and then item # into Cases, and impractical for large data
> sets.  I'm sure there is a way to Map Cases or Select over the list,
> and append the appropriate data when data set and item # match, but I
> haven't figured out how to do that.  Also it seems possible to use an
> if then statement; that if the data set and item # match then append,
> else move through the list.  However, I haven't figured out how to
> code for this either.  I appreciate any help.
>
> Thanks,
>
> Hershel

[toc] | [prev] | [standalone]


Back to top | Article view | comp.soft-sys.math.mathematica


csiph-web