Reputation: 397
My Initial Data:
library(igraph)
From <- c(1,2,3,4,5,6,7,8)
To <- c(NA,1,2,3,2,NA,6,7)
Value<- c(1,0,0.5,0.5,0,-1,-1,-0.5)
Data <- data.frame(From,To, Value)
Network <- graph.data.frame(Data[,c("From","To")])
Network<- Network - "NA"
plot(Network)
I want to know the size of the cluster they belong to. I want to combine the two functions clusters()$membership and clusters()$csize but i have no idea how i could. I want to have the belonging cluster size on each row.
Clusterx<-clusters(Network)$membership
ClusterSize<-clusters(Network)$csize
Example of possible final Data:
From <- c(1,2,3,4,5,6,7,8)
To <- c(NA,1,2,3,2,NA,6,7)
Value<- c(1,0,0.5,0.5,0,-1,-1,-0.5)
Csize<- c(5,5,5,5,5,3,3,3)
Data <- data.frame(From,To, Value,Csize)
Upvotes: 0
Views: 308
Reputation: 10825
This is a simple indexing operation.
clu <- clusters(Network)
clu$csize[ clu$membership ]
# [1] 5 5 5 5 5 3 3 3
Upvotes: 2