Question: Linking unique ID pairs
0
gravatar for floris.barthel
3.1 years ago by
floris.barthel40 wrote:

Hi!

I'm trying to link together pairs of unique IDs using R. Given the example below, I have two IDs (here ID1 and ID2) that indicate linkage. I'm trying to create groups of rows that are linked. In this example A is linked to B which is linked to D which is linked to E. Because these are all connected, I want to group them together. Next, there is also X which is linked to both Y and Z. Because these two are also connected, I want to assign them to a single group as well. How can I tackle this using R?

Thanks!

Example data:

ID1 ID2
A   B
B   D
D   E
X   Y
X   Z

DPUT R representation

structure(list(id1 = structure(c(1L, 2L, 3L, 4L, 4L), .Label = c("A", "B", "D", "X"), class = "factor"), id2 = structure(1:5,.Label = c("B", "D", "E", "Y", "Z"), class = "factor")), .Names = c("id1", "id2"), row.names = c(NA, -5L), class = "data.frame")

Output needed:

ID1 ID2 GROUP
A   B   1
B   D   1
D   E   1
X   Y   2
X   Z   2
R • 709 views
ADD COMMENTlink modified 3.1 years ago • written 3.1 years ago by floris.barthel40

A piece of etiquette about posting questions on online forums: avoid cross posting to multiple websites.

ADD REPLYlink written 3.1 years ago by WouterDeCoster40k
0
gravatar for floris.barthel
3.1 years ago by
floris.barthel40 wrote:

Solved: http://stackoverflow.com/questions/38663170/grouping-linked-unique-id-pairs-using-r#38663293

ADD COMMENTlink written 3.1 years ago by floris.barthel40
Please log in to add an answer.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 1255 users visited in the last hour