我有倍数数据格式,类似于
DF1
Element Category Subcategory Subsystem Role Fcount
E100 Cofactors, Vitamins Biotin synthesis phosphoribosyltransferase domain 1
E100 Cofactors, Vitamins Biotin synthesis Biotin operon repressor 1
E100 Cofactors, Vitamins Biotin synthesis aminotransferase (EC 2.6.1.62) 2
E100 Cofactors, Vitamins Biotin synthesis ligase (EC 6.3.4.15) 1
E100 Cofactors, Vitamins Biotin synthesis synthase (EC 2.3.1.47) 1
E100 Cofactors, Vitamins Pigments Biotin synthase (EC 2.3.1.47) 1DF2
Element Category Subcategory Subsystem Role Fcount
E200 Cofactors, Vitamins Biotin synthesis phosphoribosyltransferase domain 1
E200 Cofactors, Vitamins Biotin synthesis Biotin operon repressor 1
E200 Cofactors, Vitamins Biotin synthesis aminotransferase (EC 2.6.1.62) 2
E200 Cofactors, Vitamins Biotin synthesis toxin (EC 6.3.4.15) 1
E200 Cofactors, Vitamins Biotin synthesis synthase (EC 2.3.1.47) 1首先,从分类到角色列显示相同字符串的所有行都将被视为相等;如果一个或多个列中的字符串不同,那么它将被视为不同的行!
Example1,DF1和DF2的第1行
这两行在分类、亚类、子系统和角色列中呈现相同的模式:辅助因子、维生素生物素合成磷酸核糖转移酶结构域E 215,因此被认为是相等的!
示例2
在某些但不是全部存在的柱(如:辅助因子、维生素生物素合成连接酶(EC 6.3.4.15)和辅助因子、维生素生物素合成毒素(EC 6.3.4.15))中未出现的则为零。在DF1 (辅助因子,维生素色素生物素合成酶(EC 2.3.1.47))的最后一行中,亚类和子系统的列有差异,则必须将其作为另一行添加。
Fcount列将更改为元素的名称,并将其从列的5添加到Nnumber (在本例中为5到6列)!
最后的数据框架如下:
Category Subcategory Subsystem Role E100 E200
Cofactors, Vitamins Biotin synthesis phosphoribosyltransferase domain 1 1
Cofactors, Vitamins Biotin synthesis Biotin operon repressor 1 1
Cofactors, Vitamins Biotin synthesis aminotransferase (EC 2.6.1.62) 2 2
Cofactors, Vitamins Biotin synthesis ligase (EC 6.3.4.15) 1 0
Cofactors, Vitamins Biotin synthesis synthase (EC 2.3.1.47) 1 1
Cofactors, Vitamins Biotin synthesis toxin (EC 6.3.4.15) 0 1
Cofactors, Vitamins Pigments Biotin synthase (EC 2.3.1.47) 1 0在这个例子中,我只使用了两个数据帧,但是我有超过20个。
在R怎么能做到这一点?
对不起,如果我没有给出任何代码,但我不知道如何做!
谢谢
发布于 2021-06-24 19:27:59
有几种方法可以做到这一点,但我倾向于使用tidyverse解决方案链接到文档,您只需使用by参数即可。
df_com <- full_join(df1, df2, by = c("Category", "Subcategory", "Subsystem", "Role"))然后,您可以使用E100和E200将Fcount.x和Fcount.y列重命名为rename。还有一些基本的R和data.table解决方案,但我对它们不太熟悉
https://stackoverflow.com/questions/68121357
复制相似问题