【发布时间】:2017-10-05 19:01:45
【问题描述】:
我正在尝试抓取网站链接。到目前为止,我下载了文本并将其设置为数据框。我有以下;
keywords <- c(credit | model)
text_df <- as.data.frame.table(text_df)
text_df %>%
filter(str_detect(text, keywords))
credit 和 model 是我要搜索网站的两个值,即返回带有单词 credit 或 model in 的行。
我收到以下错误
filter_impl(.data, dots) 中的错误:找不到对象“credit”
代码只返回带有单词“model”的结果,忽略单词“credit”。
我怎样才能返回所有带有单词“credit”或“model”的结果。
我的计划是keywords <- c(credit | model | more_key_words | something_else | many values)
提前致谢。
编辑:
text_df:
Var 1 text
1 Here is some credit information
2 Some text which does not expalin any keywords but messy <li> text9182edj </i>
3 This line may contain the keyword model
4 another line which contains nothing of use
所以我试图只提取第 1 行和第 3 行。
【问题讨论】:
-
现在无法检查,但
filter_()应该可以工作 -
寻求帮助时,您应该提供reproducible example,其中包含示例输入和所需的输出。通常,您需要在 data.frames 中搜索特定列的值,而不是整个行,因此最好在这里更具体。
-
如果有帮助,我已经创建了一个简化的示例。
标签: r text-mining stringr