Hi Bert .., The number of meals differ from one customer to other customer. You may find one customer with only one meal and another one with 2,3 or even rarely 30 meals. You may also find no meal at all for some customers so the entire row takes the missing value "\N" . Any row starts with the meals codes first, then all missing values are to the right end of the table. ________________________________ From: Bert Gunter <bgunter.4567 at gmail.com> Sent: 22 May 2017 03:11:11 To: Allaisone 1 Cc: r-help at r-project.org Subject: Re: [R] Identyfing rows with specific conditions Clarification: Does each customer have the same number of meals or do they differ from customer to customer? If the latter, how are missing meals notated? Do they always occur at the (right) end or can they occur anywhere in the row? Presumably each customer ID can have many different meal code combinations, right ?(since they can have 30 different meals with potentially 30 choose 2 = 435 combinations apiece) Please make sure you reply to the list, not just to me, as I may not pursue this further but am just trying to clarify for anyone else who may wish to help. Cheers, Bert Bert Gunter "The trouble with having an open mind is that people keep coming along and sticking things into it." -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip ) On Sun, May 21, 2017 at 5:10 PM, Allaisone 1 <allaisone1 at hotmail.com> wrote:> > Hi All.., > > I have 2 tables. The first one contains 2 columns with the headers say "meal A code" & "meal B code " in a table called "Meals" with 2000 rows each of which with a different combination of meals(unique combination per row). > > >>Meals > > meal A code meal B code > > 1 34 66 > > 2 89 39 > > 3 25 77 > > The second table(customers) shows customers ids in the first column with Meals codes(M) next to each customer. There are about 300,000 customers (300,000 rows). > >> Customers > 1 2 3 4 ..30 > id M1 M2 M3 > 1 15 77 34 25 > 2 11 25 34 39 > 3 85 89 25 77 > . > . > 300,000 > > I would like to identify all customers ids who have had each meal combination in the first table so the final output would be the first table with ids attached next to each meal combination in each row like this: > >>IdsMeals > > > MAcode MBcode ids > > 1 34 39 11 > > 2 25 34 15 11 > > 3 25 77 15 85 > > Would you please suggest any solutions to this problem? > > Regards > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code.[[alternative HTML version deleted]]
You haven't said whether your "table" is a matrix or data frame. Presumably the latter. Nor have you answered my question about whether order of your meal code pairs matters. Another question: can meals be replicated for an ID or are they all different? Finally, is this a homework assignment or class project of some sort? Or is it a real task -- i.e., what is the context? Again, be sure to cc the list. -- Bert Bert Gunter "The trouble with having an open mind is that people keep coming along and sticking things into it." -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip ) On Mon, May 22, 2017 at 1:56 AM, Allaisone 1 <allaisone1 at hotmail.com> wrote:> Hi Bert .., > > > The number of meals differ from one customer to other customer. You may find > one customer with only one meal and another one with 2,3 or even rarely 30 > meals. You may also > > find no meal at all for some customers so the entire row takes the missing > value "\N" . Any > > row starts with the meals codes first, then all missing values are to the > right end of the table. > > ________________________________ > From: Bert Gunter <bgunter.4567 at gmail.com> > Sent: 22 May 2017 03:11:11 > To: Allaisone 1 > Cc: r-help at r-project.org > Subject: Re: [R] Identyfing rows with specific conditions > > Clarification: > > Does each customer have the same number of meals or do they differ > from customer to customer? If the latter, how are missing meals > notated? Do they always occur at the (right) end or can they occur > anywhere in the row? > > Presumably each customer ID can have many different meal code > combinations, right ?(since they can have 30 different meals with > potentially 30 choose 2 = 435 combinations apiece) > > Please make sure you reply to the list, not just to me, as I may not > pursue this further but am just trying to clarify for anyone else who > may wish to help. > > > Cheers, > Bert > > Bert Gunter > > "The trouble with having an open mind is that people keep coming along > and sticking things into it." > -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip ) > > > On Sun, May 21, 2017 at 5:10 PM, Allaisone 1 <allaisone1 at hotmail.com> wrote: >> >> Hi All.., >> >> I have 2 tables. The first one contains 2 columns with the headers say >> "meal A code" & "meal B code " in a table called "Meals" with 2000 rows each >> of which with a different combination of meals(unique combination per row). >> >> >>>Meals >> >> meal A code meal B code >> >> 1 34 66 >> >> 2 89 39 >> >> 3 25 77 >> >> The second table(customers) shows customers ids in the first column with >> Meals codes(M) next to each customer. There are about 300,000 customers >> (300,000 rows). >> >>> Customers >> 1 2 3 4 ..30 >> id M1 M2 M3 >> 1 15 77 34 25 >> 2 11 25 34 39 >> 3 85 89 25 77 >> . >> . >> 300,000 >> >> I would like to identify all customers ids who have had each meal >> combination in the first table so the final output would be the first table >> with ids attached next to each meal combination in each row like this: >> >>>IdsMeals >> >> >> MAcode MBcode ids >> >> 1 34 39 11 >> >> 2 25 34 15 11 >> >> 3 25 77 15 85 >> >> Would you please suggest any solutions to this problem? >> >> Regards >> >> [[alternative HTML version deleted]] >> >> ______________________________________________ >> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see >> https://stat.ethz.ch/mailman/listinfo/r-help >> PLEASE do read the posting guide >> http://www.R-project.org/posting-guide.html >> and provide commented, minimal, self-contained, reproducible code.
Dear Bert I have answered your questions in my last 2 messages. If you did not see them, I will answer again. The 2 tables are all data.frames and the order of the meals does not matter. The meal cannot be replicated for each person, they are all different. The missing values are to the right end of each row as each row starts with meal codes first. This task is just a small part of a long 2 years project. Regards ________________________________ From: Bert Gunter <bgunter.4567 at gmail.com> Sent: 22 May 2017 14:35:49 To: Allaisone 1 Cc: r-help at r-project.org Subject: Re: [R] Identyfing rows with specific conditions You haven't said whether your "table" is a matrix or data frame. Presumably the latter. Nor have you answered my question about whether order of your meal code pairs matters. Another question: can meals be replicated for an ID or are they all different? Finally, is this a homework assignment or class project of some sort? Or is it a real task -- i.e., what is the context? Again, be sure to cc the list. -- Bert Bert Gunter "The trouble with having an open mind is that people keep coming along and sticking things into it." -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip ) On Mon, May 22, 2017 at 1:56 AM, Allaisone 1 <allaisone1 at hotmail.com> wrote:> Hi Bert .., > > > The number of meals differ from one customer to other customer. You may find > one customer with only one meal and another one with 2,3 or even rarely 30 > meals. You may also > > find no meal at all for some customers so the entire row takes the missing > value "\N" . Any > > row starts with the meals codes first, then all missing values are to the > right end of the table. > > ________________________________ > From: Bert Gunter <bgunter.4567 at gmail.com> > Sent: 22 May 2017 03:11:11 > To: Allaisone 1 > Cc: r-help at r-project.org > Subject: Re: [R] Identyfing rows with specific conditions > > Clarification: > > Does each customer have the same number of meals or do they differ > from customer to customer? If the latter, how are missing meals > notated? Do they always occur at the (right) end or can they occur > anywhere in the row? > > Presumably each customer ID can have many different meal code > combinations, right ?(since they can have 30 different meals with > potentially 30 choose 2 = 435 combinations apiece) > > Please make sure you reply to the list, not just to me, as I may not > pursue this further but am just trying to clarify for anyone else who > may wish to help. > > > Cheers, > Bert > > Bert Gunter > > "The trouble with having an open mind is that people keep coming along > and sticking things into it." > -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip ) > > > On Sun, May 21, 2017 at 5:10 PM, Allaisone 1 <allaisone1 at hotmail.com> wrote: >> >> Hi All.., >> >> I have 2 tables. The first one contains 2 columns with the headers say >> "meal A code" & "meal B code " in a table called "Meals" with 2000 rows each >> of which with a different combination of meals(unique combination per row). >> >> >>>Meals >> >> meal A code meal B code >> >> 1 34 66 >> >> 2 89 39 >> >> 3 25 77 >> >> The second table(customers) shows customers ids in the first column with >> Meals codes(M) next to each customer. There are about 300,000 customers >> (300,000 rows). >> >>> Customers >> 1 2 3 4 ..30 >> id M1 M2 M3 >> 1 15 77 34 25 >> 2 11 25 34 39 >> 3 85 89 25 77 >> . >> . >> 300,000 >> >> I would like to identify all customers ids who have had each meal >> combination in the first table so the final output would be the first table >> with ids attached next to each meal combination in each row like this: >> >>>IdsMeals >> >> >> MAcode MBcode ids >> >> 1 34 39 11 >> >> 2 25 34 15 11 >> >> 3 25 77 15 85 >> >> Would you please suggest any solutions to this problem? >> >> Regards >> >> [[alternative HTML version deleted]] >> >> ______________________________________________ >> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see >> https://stat.ethz.ch/mailman/listinfo/r-help >> PLEASE do read the posting guide >> http://www.R-project.org/posting-guide.html >> and provide commented, minimal, self-contained, reproducible code.[[alternative HTML version deleted]]