所以我现在有一个工作数据框,但我想研究数据框主题的起源。这是我用来创建数据框的一些代码:
df <- as.data.frame(t(test)) #This is so the row names are products
vertices <- row.names(df)
place <- colnames(df)
L <- length(vertices)
numedges <- choose(L,2)
edges <- data.frame(v1=rep(NA, numedges), v2=NA, numrows=NA, location=NA)
k <- 0
for(i in 1:(L-1)) {
for(j in (i+1):L) {
k <- k + 1
edges$v1[k] <- vertices[i]
edges$v2[k] <- vertices[j]
edges$numrows[k] <- sum(df[vertices[i], ]=="Yes" & df[vertices[j], ]=="Yes")
edges$location[k] ### Here is my problem!!!
}}
我希望输出看起来像:
edges
v1 v2 numrows location #What I would like to see
1 Fish Squid 8 Town 1, Town 2, Town 4
2 Fish Fruits 0 Town 1
3 Fish Wood 0 Town 1
4 Fish Etc 2 Town 1, Town 2
5 Fish Corn 1 Town 1
我认为 numrows 成为所有边缘的总和?如果我错了,请纠正我。所以我想收集所有满足 numrow 函数的位置。