返回部分匹配的字符串字符的值

时间:2016-06-27 07:51:20

标签: r grepl

我有两个数据框

> df1
      A            B
1MG               70
ABOF              52  
Amazon            12
American Swan     10
Clovia            12


> df2

      A                            B                                         
1 MG Solution
ABOF Prime
Dual Command
Amazon AWF
American Swan Financial Services 
Clovia World Spaces
Shape Makers 
Unions

我想返回从df1df2的部分匹配字符的值。例如,亚马逊在df1df2中的值为12,我希望在包含亚马逊的每个字符串前面返回此值。如果没有找到,请返回NA

result_df是我期待的预期输出。

> reslut_df

      A                             B                      
1 MG Solution                       70
ABOF Prime                          52
Dual Command                        NA
Amazon AWF                          12
American Swan Financial Services    10
Clovia World Spaces                 12 
Shape Makers                        NA
Unions                              NA

0 个答案:

没有答案