r - 为什么我的停用词不会删除 R 数据框中的“?&”?
问题描述
我在数据框中有一列,old_df
.
示例行如下所示:
data
trying URL 'https://maps.googleapis.com/maps/api/streetview?&location=13.5146367326733,100.380686367492&size=8000x5333&heading=0&fov=90&pitch=0&key='Content type 'image/jpeg' length 59782 bytes (58 KB)
downloaded 58 KB
使用stopwords
,我删除了我不想要的单词,并留下:
data
?&13.5146367326733,100.380686367492
?&13.5162026732673,100.66581378616
stopwords = c('trying',
'URL',
"'",
'&',
'location=',
'https://maps.googleapis.com/maps/api/streetview',
'size=8000x5333',
'heading',
'=0&fov=90&pitch=0&key=',
'Content',
'type',
'image/jpeg',
'length',
'bytes',
'KB')
require('tm')
new_df <- as.data.frame(removeWords(old_df$data, stopwords))
但是,?&
保留在data
数字之前的列中(我不想要)。我尝试将和in包括?
在内,但它们仍然存在。任何想法如何删除它们?&
?&
stopwords
事实上,当我在 中包含上述组合时stopwords
,我得到了错误:
PCRE pattern compilation error 'quantifier does not follow a repeatable item' at '?|&|')\b'
解决方案
使用gsub()
. 停用词只删除被空格包围的“单词”。
Base R
解决方案:
gsub("^\\?&", "", old_df$data)
stringr
解决方案:
library(stringr)
stringr::str_remove(old_df$data, "^\\?&")
推荐阅读
- python - 使用 python docx 替换 Word doc 中的现有表
- css - 如何防止引导列在移动宽度下相互移动?
- c++ - 从文本文件行获取并拆分它们
- c++ - 如何改进搜索二项式系数的递归算法
- r - 使用正则表达式从邮件中提取句子
- azure-devops - Azure DevOps 服务连接限制不适用于发布管道
- c# - 如何仅使用 tasks.json 中的一个命令在 VS Code 中构建所有 C# 项目?
- javascript - 如何在 FeathersJS 服务扩展中使用 app.service('myService')?
- c# - 带有 XML 内容的 POST 请求始终为空 C#
- javascript - 使用 Flask 时在 javascript 中导入的正确方法