R:如何获得邻接矩阵,但在第三列的交点值? [英] R: How to get something like adjacency matrix, but on the intersection value of third column?

查看:593
本文介绍了R:如何获得邻接矩阵,但在第三列的交点值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这样的数据框架:

      V1     V2     LABEL
    1 83965 891552   A
    2 88599 891552   B
    3 42966 891552   C
    4 83965 891553   D
    5 88599 891553   D
    6 42966 891553   B

如何将其转换为邻接矩阵,但是在我想要的colum-row的交集中,第三个列的值就是这样:

How can I convert it to something like adjacency matrix, but on the intersection of colum-row i would like to have, the third colum value, like that:

        891552 891553
  42966      C      B
  83965      A      D
  88599      B      D

@Henrik

我有这样的错误。我认为这个分段失败是由大量数据引起的。

I got such error. I think this segmentfault is caused by big size of data.

Using label as value column: use value.var to override.
Aggregation function missing: defaulting to length

 *** caught segfault ***
address 0x7fff1e099a90, cause 'memory not mapped'

Traceback:
 1: .Call("split_indices", group, as.integer(n))
 2: split_indices(.group, .n)
 3: vaggregate(.value = value, .group = overall, .fun = fun.aggregate,     ..., .default = fill, .n = n)
 4: cast(data, formula, fun.aggregate, ..., subset = subset, fill = fill,     drop = drop, value.var = value.var)
 5: dcast(dat, item ~ worker)
Any idead how it is possible to get rid of it?

我放弃了R和我使用Python的trys,因为所有的解决方案:但是,如果你知道一些解决方案,可以通过大量数据进行有效的处理,让我知道

推荐答案

您可以尝试这个,其中 df 是您的数据框架:

You may try this, where df is your data frame:

library(reshape2)
dcast(df, V1 ~ V2)

#      V1 891552 891553
# 1 42966      C      B
# 2 83965      A      D
# 3 88599      B      D

这篇关于R:如何获得邻接矩阵,但在第三列的交点值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆