mardi 3 juillet 2018

Multiple pattern/string matching in R

I have two data frames one is a map with over 20000 possibilities, another one contains 3 columns of 30000 rows of data. I need to use the map to figure out the correct name. Here is a simple example of what I need:

For instance,

>data
V1 V2
aa ff
bb gg
aa hh
cc yy
dd jj
ee kk
aa hh

>map
V1 V2 
aa 1
gg 2
cc 3
jj 4
kk 5

>what.I.need
V1 V2 V3
aa ff 1
bb gg 2
aa hh 1
cc yy 3
dd jj 4
ee kk 5
aa hh 1

I tried using grep, but I can't seem to figure out how to make it work with a map of 20000 possibilities and have it populate the 3rd column in "what.I.need". Thank you in advance.

Aucun commentaire:

Enregistrer un commentaire