【发布时间】:2014-09-12 07:16:38
【问题描述】:
借助包/驱动程序RNeo4j (https://github.com/nicolewhite/Rneo4j),可以在R 中使用流行的图形数据库Neo4j。
包作者@NicoleWhite在GitHub上提供了severalgreat examples的用法。
不幸的是,@NicoleWhite 给出的示例和文档有点过于简单,因为它们手动创建了每个图形节点及其关联的labels 和properties,例如:
mugshots = createNode(graph, "Bar", name = "Mugshots", location = "Downtown")
parlor = createNode(graph, "Bar", name = "The Parlor", location = "Hyde Park")
nicole = createNode(graph, name = "Nicole", status = "Student")
addLabel(nicole, "Person")
当您处理一个很小的示例数据集时,这一切都很好,但这种方法不适用于像拥有数千个用户的大型社交图,其中每个用户都是一个节点(这样的图可能无法利用每个查询中的每个节点,但它们仍然需要输入到Neo4j)。
我试图弄清楚如何使用向量或数据框来做到这一点。是否有解决方案,可能涉及apply 语句或for 循环?
这个基本的尝试:
for (i in 1:length(df$user_id)){
paste(df$user_id[i]) = createNode(graph, "user", name = df$name[i], email = df$email[i])
}
导致Error: 400 Bad Request
【问题讨论】:
-
为什么要使用 paste 函数为 df$user_id[i] 赋值?
标签: r neo4j graph-databases r-neo4j