Reputation: 125
I have two datasets:
First Dataset -
A B C D E F
Cat 1 0 1 0 0 1
Dog 0 1 1 0 0 0
Fish 1 1 1 1 0 0
Frog 0 0 0 0 0 1
Second Dataset
A B C D E F
Cat 2.3 1.4 3.6 7.2 1.3 1.2
Dog 1.2 1.7 1.9 2.3 4.5 6.3
Fish 1.1 1.2 2.4 3.6 3.8 0.2
Frog 1.5 1.9 2.3 5.4 2.3 4.5
How do make a new matrix/dataset so that all the ones in the first dataset becomes the value in the second dataset, and all the zeros in dataset one stay the same. For example, I want to combine the first and second dataset I just made into:
| A | B | C | D | E | F |
----|-----|-----|-----|-----|----|-----|
Cat | 2.3 | 0 | 3.6 | 0 | 0 | 1.2 |
----|---- |-----|-----|-----|----|-----|
Dog | 0 |1.7 | 1.9 | 0 | 0 | 0 |
----|-----|-----|-----|-----|----|-----|
Fish| 1.1 |1.2 | 2.4 | 3.6 | 0 | 0 |
----|-----|-----|-----|-----|----|-----|
Frog| 0 | 0 | 0 | 0 | 0 | 4.5 |
Upvotes: 2
Views: 67
Reputation: 23788
No need to transform to a matrix:
> df1*df2
A B C D E F
Cat 2.3 0.0 3.6 0.0 0 1.2
Dog 0.0 1.7 1.9 0.0 0 0.0
Fish 1.1 1.2 2.4 3.6 0 0.0
Frog 0.0 0.0 0.0 0.0 0 4.5
Upvotes: 6