This question is continues of the question.
I have the n
points with (x, y)
coordinates organised in matrix like this:
A <- t(matrix(c(
0, 0, 1, 0, 1,-1, 1,-2, 0,-2,-1,-2,-2,-2,-2,-1,-1,-1, 0,-1, 0, -2, 0,-3,
0,-4,-1,-4,-1,-3,-1,-2, 0,-2, 1,-2, 2,-2, 2,-3, 1,-3, 0,-3, 0,-2, 0,-1, 0, 0), nrow =2));
As you can see k=8
pairs have repeated (x,y)
coordinates.
Edit.
ids <- which(duplicated(A))
k <- length(ids)
I have created the igraph object g
and plot it. The nodes with repeated coordinates are denoted by red color on the figure. Some of them are repeated twice, and some three or even four times.
library(igraph)
g <- make_empty_graph(n=nrow(A))
g <- g + path(seq_len(nrow(A)))
V(g)$id <- seq_len(vcount(g))
V(g)[V(g)$id %in% ids]$color <- "red"
plot(g, layout=as.matrix(A),
edge.arrow.size = 0.3,
edge.curved = TRUE
)
I need to merge the nodes with repeated coordinates into one node.
Question. Is it possible to merge the nodes with repeated coordinates into one node? The repeated edges should be union into the one edge too. Direction of edges can be omitted.