【发布时间】:2016-03-11 14:07:32
【问题描述】:
我有一个包含页面路径的数据框列(我们称之为 A):
pagePath
/text/other_text/123-string1-4571/text.html
/text/other_text/string2/15-some_other_txet.html
/text/other_text/25189-string3/45112-text.html
/text/other_text/text/string4/5418874-some_other_txet.html
/text/other_text/string5/text/some_other_txet-4157/text.html
/text/other_text/123-text-4571/text.html
/text/other_text/125-text-471/text.html
我还有另一个字符串数据框列,我们称之为 (B)(两个数据框不同,它们的行数不同)。
这是我在数据框 B 中的列的示例:
names
string1
string11
string4
string3
string2
string10
string5
string100
我要做的是检查我的页面路径 (A) 是否包含来自其他数据框 (B) 的字符串。
我遇到了困难,因为我的两个数据框长度不同,而且数据没有组织。
预期输出
我希望得到这个输出结果:
pagePath names exist
/text/other_text/123-string1-4571/text.html string1 TRUE
/text/other_text/string2/15-some_other_txet.html string2 TRUE
/text/other_text/25189-string3/45112-text.html string3 TRUE
/text/other_text/text/string4/5418874-some_other_txet.html string4 TRUE
/text/string5/text/some_other_txet-4157/text.html string5 TRUE
/text/other_text/123-text-4571/text.html NA FALSE
/text/other_text/125-text-471/text.html NA FALSE
如果我的问题需要进一步澄清,请提及。
【问题讨论】:
-
A$pagePath[B$pagePath]? -
@mtoto 我想检查我的 A 列是否包含来自 B 列的数据(A 列和 B 列中的数据不相等,但有时 A 列包含 B 列中的数据)
-
@sarah 我认为你应该检查一下 R 中的匹配功能。
-
请展示
B的示例以及您的预期输出。 -
@mtoto 我编辑了我的问题并写了一个 B 的例子。