I have two data frames, DF1 has many columns and tag
column which has duplicate values:
... tag
... cat
... dog
... cat
... pencil
... ...
DF2 has two columns, tag
and type
, tag
values are unique, type
are not:
tag type
car vehicle
cat animal
dog animal
pencil object
... ...
It's not necessarily true that each tag from DF1 is described in DF2. I'd like to add column to DF1 which would contain type for each tag, for example:
... tag type
... cat animal
... dog animal
... cat animal
... pencil object
... ...
Type for any tags from DF1 which are not in DF2 should be NA.
I made a loop to solve this, but it's very slow for a bigger data set. I assume that something like this can be done more elegant in R?