[R] Conversion to Adjacency Matrix

Chuck Cleland ccleland at optonline.net
Sat Feb 18 16:25:20 CET 2006


   I have data in the following form:

ID COUPON0 COUPON1 COUPON2 COUPON3
  1       1    1000    1001    1002
  2       2      NA      NA      NA
  3    1000    1003      NA    1004
  4    1001      NA    1005      NA
  5    1002      NA      NA      NA
12    1003      NA      NA    1006
  7    1005      NA      NA      NA
  8    1004    1007      NA      NA
  9    1006      NA      NA      NA
26    1007      NA      NA      NA

   I would like to convert this into an adjacency matrix like the following:

     1  2  3  4  5 12  7  8  9 26
  1  0  0  1  1  1  0  0  0  0  0
  2  0  0  0  0  0  0  0  0  0  0
  3  0  0  0  0  0  1  0  1  0  0
  4  0  0  0  0  0  0  1  0  0  0
  5  0  0  0  0  0  0  0  0  0  0
12  0  0  0  0  0  0  0  0  1  0
  7  0  0  0  0  0  0  0  0  0  0
  8  0  0  0  0  0  0  0  0  0  1
  9  0  0  0  0  0  0  0  0  0  0
26  0  0  0  0  0  0  0  0  0  0

   The actual data contains about 570 rows and 7 "coupon" columns. 
COUPON0 is a unique coupon number submitted by each participant. 
COUPON1-COUPON7 are unique coupon numbers distributed to other 
participants.  About 15 participants were "seeds" who distributed coupon 
numbers but did not receive a coupon from another participant.  Many 
participants (including some seeds) did not distribute any coupons.
   Any ideas about how to make this conversion would be greatly appreciated.

-- 
Chuck Cleland, Ph.D.
NDRI, Inc.
71 West 23rd Street, 8th floor
New York, NY 10010
tel: (212) 845-4495 (Tu, Th)
tel: (732) 452-1424 (M, W, F)
fax: (917) 438-0894




More information about the R-help mailing list