使用 qdap 清理文本
qdap 包还提供了其他文本清理函数。每个函数都有其用途,结合使用时尤其强大。
bracketX():移除括号内的所有文本(例如,"It's (so) cool" 会变成 "It's cool")replace_number():将数字替换为对应的英文单词(例如,"2" 会变成 "two")replace_abbreviation():将缩写替换为完整形式(例如,"Sr" 会变成 "Senior")replace_contraction():将缩略形式还原为基础词(例如,"shouldn't" 会变成 "should not")replace_symbol():将常见符号替换为对应的英文单词(例如,"$" 会变成 "dollar")
本练习是课程的一部分
使用 R 的 Bag-of-Words 进行文本挖掘
练习说明
请将以下函数应用到上一个练习中的 text 对象:
bracketX()replace_number()replace_abbreviation()replace_contraction()replace_symbol()
交互式实操练习
通过完成这段示例代码来试试这个练习。
## text is still loaded in your workspace
# Remove text within brackets
___
# Replace numbers with words
___
# Replace abbreviations
___
# Replace contractions
___
# Replace symbols with words
___