创建具有多个列的Edgelist,n/as在R中
正在研究R。
我
看起来有点像这样:
V1 V2 V3 V4
1 1 2 3 NA
2 2 3 NA NA
3 2 4 1 NA
4 1 NA NA NA
但是更大。我很难从这些数据中创建Edgelist并尝试过:
myPairs <- apply(t(df), 2, function(x) t(combn(x[!is.na(x)], 2)))
但是继续遇到此错误:
h(simpleerror(msg,call))中的错误:评估参数的错误 'x'在选择功能't'的方法时:n&lt; m
输出应该看起来像这样:
col1 col2
1 1 2
2 1 3
3 2 3
4 2 3
5 2 4
6 2 1
7 1 4
任何帮助都将不胜感激!
I am working on igraph in R.
I have a dataframe (df) with 29 columns - some rows which all have values and some which have NA
s.
It looks a little something like this:
V1 V2 V3 V4
1 1 2 3 NA
2 2 3 NA NA
3 2 4 1 NA
4 1 NA NA NA
but much larger. I am having trouble creating an edgelist from this data and have tried:
myPairs <- apply(t(df), 2, function(x) t(combn(x[!is.na(x)], 2)))
but keep getting this error:
Error in h(simpleError(msg, call)) : error in evaluating the argument
'x' in selecting a method for function 't': n < m
The output should look like this:
col1 col2
1 1 2
2 1 3
3 2 3
4 2 3
5 2 4
6 2 1
7 1 4
Any help would be very much appreciated!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是一种方法。
确保您的data.frame是数字:
您可以在完成
上使用
,但首先使用应用
combnna.omit
缺少值。您还可以检查length
,因此,如果您一排仅具有一个值,则会跳过它。输出
Here is one approach.
Making sure your data.frame is numeric:
You can use
apply
withcombn
as you've done, but first usena.omit
to remove missing values. You can also check thelength
so that if you only have one value in a row you skip it.Output