如何基于其他两个数据帧创建一个数据帧?

时间:2019-05-13 21:10:10

标签: r dataframe merge igraph social-networking

我正在igraph中使用动物社交网络来开发R。我需要基于用于构建网络的两个原始数据框创建一个数据框。

节点:https://1drv.ms/t/s!AmcVKrxj94WClv8yQyqyl4IWk5mNvQ

链接:https://1drv.ms/t/s!AmcVKrxj94WClv8z_Pow5Tg2U7mjLw

我的目标是生成一个边缘列表(链接),其中包括连接所涉及的节点的属性。我将使用它来进行分类分析,以测试相邻结点是否具有相似的生物学特性。

我尝试使用不同的合并功能,但无法获得所需的结果。

nodes <- read.delim("nodes.txt")
links <- read.delim("links.txt")

head(nodes)

name             species   code class1 duration maximum minimum peak note bandwidth
1 species1         Boana_faber Boafab class1    101.0    1985     315  950 0.12      1670
2 species2  Boana_albopunctata Boaalb class1      2.0    2722    1636 1975 0.40      1085
3 species3 Physalaemus_cuvieri Phycuv class1      3.7    1305     453  602 0.70       851
4 species4        Boana_lundii Boalun class1      0.9    1576     365  643 0.10      1211
5 species5     Rhinella_ornata Rhiorn class1      1.5     960     580  775 0.02       380
6 species6   Rhinella_dypticha Rhidyp class1      3.0    1174     566  849 0.30       607

head(links)

      from       to weight type1 season
1 species1 species2    291 type1  rainy
2 species1 species2     18 type1    dry
3 species1 species3    158 type1  rainy
4 species1 species4     70 type1  rainy
5 species1 species4     24 type1    dry
6 species1 species5     30 type1  rainy

结果数据框应如下所示:

node1       node2 weight type1 season duration1 duration2 maximum1 maximum2 ...
1 species1 species2    291 type1  rainy ...
2 species1 species2     18 type1    dry
3 species1 species3    158 type1  rainy
4 species1 species4     70 type1  rainy
5 species1 species4     24 type1    dry
6 species1 species5     30 type1  rainy

非常感谢您的帮助!

0 个答案:

没有答案
相关问题