I have a simple question on grouping data. Take the data frame:
df <- data.frame(c(1,2,3,5,5),c(2,3,4,7,6))
colnames(df)<- c(\"A\",\"B\")
df
A B
1 1 2
2
You can use a network graph of the data with the igraph package.
library(igraph)
g <- graph.data.frame(df)
plot(g)
From the plot we can see the components of the graph of g
and how they relate to each other.
I don't use this package very often, but it seems like the way to get the components is to use get.vertex.attribute()
, as shown below.
lapply(decompose.graph(g), get.vertex.attribute, "name")
# [[1]]
# [1] "1" "2" "3" "4"
#
# [[2]]
# [1] "5" "7" "6"