forked from briatte/ggnet
-
Notifications
You must be signed in to change notification settings - Fork 1
/
functions.R
62 lines (58 loc) · 1.39 KB
/
functions.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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#
# group results
#
by.group <- function(f) {
t = table(ids$Groupe[which(ids$Twitter %in% f)])
print(t)
print(round(t / sum(t), 2))
}
#
# who is followed by...
#
who.is.followed.by <- function(net, x) {
f = net[which(net$Source == x), ]$Target
by.group(f)
return(list(node = x, follows = as.character(f)))
}
# examples
# x = who.is.followed.by(net, "JacquesBompard")
# str(x)
# y = who.is.followed.by(net, "Marion_M_Le_Pen")
# str(y)
#
# who follows...
#
who.follows <- function(net, x) {
f = net[which(net$Target == x), ]$Source
by.group(f)
return(list(node = x, followers = as.character(f)))
}
# examples
# x = who.follows(net, "nk_m")
# str(x)
# y = who.follows(net, "marclefur")
# str(y)
#
# within-group indegree
#
top.group.inlinks <- function(net, x) {
x = ids$Twitter[which(ids$Groupe %in% x)]
f = subset(net, Source %in% x & Target %in% x)
f = data.frame(table(f$Target))
return(head(f[order(f$Freq, decreasing = TRUE), ]))
}
# examples
# top.group.inlinks(net, "SRC")
# lapply(levels(ids$Groupe), top.group.inlinks, df = df)
#
# within-group outdegree
#
top.group.outlinks <- function(net, x) {
x = ids$Twitter[which(ids$Groupe %in% x)]
f = subset(net, Source %in% x & Target %in% x)
f = data.frame(table(f$Source))
return(head(f[order(f$Freq, decreasing = TRUE), ]))
}
# examples
# top.group.outlinks(net, "Ecolo")
# lapply(levels(ids$Groupe), top.group.outlinks, df = df)