我有两个数据帧:df1
plot grass moss rock other stuff
a 4 0 0 text 3
b 2 2 3 text 4
c 10 0 0 text 0
d 3 1 0 text 9
和df2
Cover value
grass 5
moss 2
rock 3
我想将df1中的值乘以df2中的相应值 . 该解决方案应适用于大型数据集 .
结果df3
plot grass moss rock
a 20 0 0
b 10 4 9
c 50 0 0
d 15 2 0
1 回答
你的数据:
(确保
Cover
是此解决方案的字符向量,而不是因子 . )一个简单的
for
循环就可以了: