【发布时间】:2017-10-26 03:12:10
【问题描述】:
我正在尝试创建一个仅保留一个数据集中存在于另一个数据集中的单词的数据集。我知道如何在 Python 中执行此操作,但需要在 R 中执行此操作。 这是两个示例数据集。我想从 text_A 返回 text_B 中存在的单词。
text_A= ['apple','cherry','kiwi','Tangerine','apple','apple','kiwi']
text_B= ['apple','banana','grapefruit','kiwi','mango','papaya', 'tangerine']
combined_words= [ ]
for x_words in text_A:
if x_words in text_B:
combined_words.append(x_words)
print(combined_words)
输出应该是: '苹果','猕猴桃','apple','apple','猕猴桃'
【问题讨论】:
-
你的意思是
intersect(text_A, text_B)?