[R] Find "undirected" duplicates in a tibble

Greg Minshall m|n@h@|| @end|ng |rom um|ch@edu
Fri Aug 20 16:13:06 CEST 2021


> x %>% transmute( a=pmin(Source,Target), b=pmax(Source,Target)) %>%
>   unique() %>% rename(Source=a, Target=b)

ah, very nice.  i have trouble remembering, e.g., unique().

fwiw, (hopefully) here's a baser version.
  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(A=min(y), B=max(y))))

cheers, Greg

More information about the R-help mailing list