[R] Combinations of values in two columns

Thomas thomas.chesney at nottingham.ac.uk
Fri Nov 1 10:32:09 CET 2013

I have data that looks like this:

Friend1, Friend2
A, B
A, C
B, A
C, D

And I'd like to generate some more rows and another column. In the new  
column I'd like to add a 1 beside all the existing rows. That bit's  
easy enough.

Then I'd like to add rows for all the possible directed combinations  
of rows not included in the existing data. So for the above I think  
that would be:

A, D
D, A
B, C
C, B
B, D
C, A
D, B
D, C

and then put a 0 in the column beside these.

Can anyone suggest how to do this?

I'm using R version 2.15.3.

Thank you,

Thomas Chesney
This message and any attachment are intended solely for the addressee and may contain confidential information. If you have received this message in error, please send it back to me, and immediately delete it.   Please do not use, copy or disclose the information contained in this message or in any attachment.  Any views or opinions expressed by the author of this email do not necessarily reflect the views of the University of Nottingham.

This message has been checked for viruses but the contents of an attachment
may still contain software viruses which could damage your computer system, you are advised to perform your own checks. Email communications with the University of Nottingham may be monitored as permitted by UK legislation.

More information about the R-help mailing list