Skip to content
Back to formatted view

Raw Message

Message-ID: <732064.1629457943@apollo2.minshall.org>
Date: 2021-08-20T11:12:23Z
From: Greg Minshall
Subject: Find "undirected" duplicates in a tibble
In-Reply-To: Your message of "Fri, 20 Aug 2021 08:59:34 +0000." <47d240b33b929af0e3aed792bec69d929756c684.camel@utu.fi>

Kimmo,

i'll be curious to see other, maybe more elegant, answers.  in the
meantime, this seems to work.

----
  x = data.frame(Source=rep(1:3,4), Target=c(rep(1,3),rep(2,3),rep(3,3),rep(4,3)))
  y <- apply(x, 1, function(y) return (c(n=min(y), x=max(y))))
  res <- data.frame()
  for (n in unique(y["n",])) {
    unique(y["x",y["n",]==n])
    res <- rbind(res, data.frame(A=c(n), B=unique(y["x",y["n",]==n])))
  }
  res
----

thanks for the question!

cheers, Greg