I have two dataframes, I want to subtract the value of column in one dataframe to another, if dataframes are equal in value of another column.
I have two dataframes A and B that are similar to the following:
[A]
Col1 Col2
1 cat
2 dog
3 bird
4 cat
5 dog
[B]
Col1 Col2
[cat] 1
[dog] 2
[bird] 3
I want to be able to add the values A$Col1 + B$Col2
if A$Col2
matches the tag of [B]
and create a list with the results that will have the same length as the rows in [A]
I have tried this code
(A$Col1-B$Col2)[A$Col2==B$Col1]
which seems to work, but a following warning shows up:
longer object length is not a multiple of shorter object length