#' return same distribtuion random nodes
#' @param graph network object
#' @param dist distribution calcualted by histogram counts
#' @param names the names vector for selection
dist.sample <- function(graph, dist,names){
v.name.list <- c()
n <- length(dist)
dist<-dist[2:n]
for(i in 1:(n-1)){
count<-dist[i]
subset.withdegree <- V(graph)$name[(degree(graph,V(graph))==i | degree(graph,V(graph))==i+1 | degree(graph,V(graph))==i-1)&
(V(graph)$name %in%names==T)&(V(graph)$name%in%v.name.list==F)]
#print(c(i,count,length(subset.withdegree)))
# if(length(subset.withdegree)==0) {
# next
# }
t=0
while(t<60 & (length(subset.withdegree)==0 && count!=0 && length(subset.withdegree)<count)){
subset.withdegree <- V(graph)$name[(degree(graph,V(graph))==i | degree(graph,V(graph))<=i+t | degree(graph,V(graph))>=i-t)& (V(graph)$name %in%names==T)&(V(graph)$name%in%v.name.list==F)]
t=t+1
}
sample.subset <- if((length(subset.withdegree)!=0 && count!=0 && length(subset.withdegree)>=count)) sample(subset.withdegree,count)else(NA)
v.name.list <- append(v.name.list,sample.subset)
}
#print(v.name.list)
v.name.list<-v.name.list[!is.na(v.name.list)]
return(v.name.list)
in.sub <- induced_subgraph(graph,v.name.list)
in.sub
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.