r - 从列中删除所有数字
问题描述
使用它可以删除 nbsp
str_replace_all(df$text, 'nbsp', '')
有人可以使用哪种正则表达式通过此命令删除所有数字?
解决方案
如果通过“nbsp”您指的是非中断空间,那么它应该通过使用显式 Unicode 编码来工作。
nbsp以0x00A0
Unicode编码,因此在 R 上您可以将其表示为"\U00a0"
.
例如:
> "This is a strange\U00A0 character"
[1] "This is a strange character"
使用不同的字符可能会更清楚:
> "This is a strange \U00A1 character"
[1] "This is a strange ¡ character"
这可以像您期望的那样被删除。
> str_remove("This is a strange \U00A1 character", "\U00A1")
[1] "This is a strange character"
> str_remove("This is a strange\U00A0 character", "\U00A0")
[1] "This is a strange character"
这也可以通过提供十进制表示法来工作:
str_remove("This is a strange\U00A0 character", intToUtf8(160))
请注意,这适用于我的计算机,但安装的区域设置和字体可能会有所不同。
推荐阅读
- python - RuntimeError:当 `enforce_sorted` 为 True 时,`lengths` 数组必须按降序排序。- 火炬
- reactjs - React Apollo 客户端多个突变
- mongodb - 并发请求的MongoDB内存管理
- webpack - 当extractCss为真时,如何在head标签中获取特定css文件的内联样式?
- javascript - 加载所有图像后更新组件的状态
- swift - RealityKit – 如何为自然光创建阴影捕捉器?
- angular - 仅在单击按钮 angular 后才显示我的搜索
- arrays - 从对象中获取未知的“标签”
- python - 具有平方根的 Python pyplot 文本
- mysql - 为什么添加列返回时Mysql查询变慢?