-
Notifications
You must be signed in to change notification settings - Fork 0
/
util.R
32 lines (26 loc) · 958 Bytes
/
util.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
library(igraph)
create.matrix <- function(vertex, friends,out=TRUE){
if(out){
result <- matrix(c(rep(vertex, length(friends)),friends),ncol=2,nrow=length(friends))
}else{
result <- matrix(c(friends, rep(vertex, length(friends))),ncol=2,nrow=length(friends))
}
return(result)
}
relation.reciprocity <- function(graph, vertex){
os <- neighbors(graph,V(graph)[vertex],mode="out")
is <- neighbors(graph,V(graph)[vertex],mode="in")
length(intersect(os,is))/length(os)
}
get.path <- function(network,file){
paste("~/code/R/googleplus/",network, '/data/',file, sep="")
}
create.ggplot.data.frame <- function(datasets, column){
graph.names <- names(datasets)
networks <- unlist(lapply(graph.names,function(x){rep(x,length(datasets[[x]][,1]))}))
values <- c()
for(dataset in datasets){
values <- c(values,dataset[order(dataset[column],decreasing=T),][[column]])
}
data.frame(network=as.factor(networks),value=values)
}