首先,我对R不是很精通,但我有一个100个节点的网络,我正在做分析.我想找到网络中每对节点之间的所有最短路径(100次计算),诀窍是将它们作为整数返回,路径长度如果你愿意的话.
#construct a small sample of the graph
g = graph.formula('insert graph')
#use the function to retrieve shortest paths from a single vertex
get.all.shortest.paths(g, 1, to = V(g))
#output
$res
$res[[1]]
[1] 1
$res[[2]]
[1] 1 2
$res[[3]]
[1] 1 2 3
$res[[4]]
[1] 1 2 3 4
$res[[5]]
[1] 1 2 3 4 5
$res[[6]]
[1] 1 10 9 8 7 6
$res[[7]]
[1] 1 2 3 4 5 6
$res[[8]]
[1] 1 10 9 8 7
$res[[9]]
[1] …Run Code Online (Sandbox Code Playgroud) 我现在开始使用这个界面,我有一些Python的经验但没什么广泛的.我正在计算一个小图的传递性和社区结构:
import networkx as nx
G = nx.read_edgelist(data, delimiter='-', nodetype=str)
nx.transitivity(G)
#find modularity
part = best_partition(G)
modularity(part, G)
Run Code Online (Sandbox Code Playgroud)
我得到了传递性,但是 - 计算模块性存在以下错误.
NameError: name 'best_partition' is not defined
Run Code Online (Sandbox Code Playgroud)
我只是按照networkx网站提供的文档,有什么我做错了吗?
我有数百个看起来像这样的词典.它们都有相同的键(纽约,芝加哥等......)但具有不同的值.没有遗漏的值.
[{'New York': 'cloudy', 'Chicago': 'snowy', 'Seattle': 'rainy'},
{'New York': 'cloudy', 'Chicago': 'hailing', 'Seattle': 'sunny'},
{'New York': 'sunny', 'Chicago': 'snowy', 'Seattle': 'rainy'},
{'New York': 'hailing', 'Chicago': 'snowy', 'Seattle':'snowy'}]
Run Code Online (Sandbox Code Playgroud)
我想计算每个键最常见的"天气"值.然后将它们全部合并到一个最终列表中,该列表仅输出具有其最常见键值的每个城市.
{'New York': 'cloudy', 'Chicago': 'snowy', 'Seattle': 'rainy'}
Run Code Online (Sandbox Code Playgroud)
我怎样才能做到这一点?
我有一个如下所示的向量:
> vector <- c("1","2","0", "10", "name", "hello")
Run Code Online (Sandbox Code Playgroud)
我想将其转换为每个数字字符变成一个字符串,而不影响实际的字符串。
[1] "test" "test" "test" "test" "name" "hello"
Run Code Online (Sandbox Code Playgroud)
我怎样才能做到这一点?