我对 R 真的很陌生,遇到了以下问题。我的数据框看起来像这样。
> Entity Substance conc..mM. variable value
1 STD5 Sulfate 5.000 Area 70761
2 STD5 Formate 5.000 Area NA
3 STD5 Acetate 5.000 Area 70777
4 STD5 Lactate 5.000 Area 74329
5 STD5 Propionate 5.000 Area 84198
6 STD5 Butyrate 5.000 Area 91598
7 STD5 Valeriate NA Area 40609
8 STD5 Caproate NA Area 40763
9 STD2_5 Sulfate 2.500 Area 34350
10 STD2_5 Formate 2.500 Area NA
11 STD2_5 Acetate 2.500 Area 34863
12 STD2_5 Lactate 2.500 Area 36262
13 STD2_5 Propionate 2.500 Area 41849
14 STD2_5 Butyrate 2.500 Area 44574
15 STD2_5 Valeriate 2.500 Area 39664
16 STD2_5 Caproate 2.500 Area 39867
现在我想添加一个列,其中给定实体的每一行都包含来自相应实体的 caproate 值。有没有聪明的方法来实现这一目标?
预期产出
> Entity Substance conc..mM. variable value area caproate
1 STD5 Sulfate 5.000 Area 70761 40763
2 STD5 Formate 5.000 Area NA 40763
3 STD5 Acetate 5.000 Area 70777 40763
4 STD5 Lactate 5.000 Area 74329 40763
5 STD5 Propionate 5.000 Area 84198 40763
6 STD5 Butyrate 5.000 Area 91598 40763
7 STD5 Valeriate NA Area 40609 40763
8 STD5 Caproate NA Area 40763 40763
9 STD2_5 Sulfate 2.500 Area 34350 39867
10 STD2_5 Formate 2.500 Area NA 39867
11 STD2_5 Acetate 2.500 Area 34863 39867
12 STD2_5 Lactate 2.500 Area 36262 39867
13 STD2_5 Propionate 2.500 Area 41849 39867
14 STD2_5 Butyrate 2.500 Area 44574 39867
15 STD2_5 Valeriate 2.500 Area 39664 39867
16 STD2_5 Caproate 2.500 Area 39867 39867