r - 大写基本方向,对 R 中的所有其他内容使用标题大小写
问题描述
我有一个大写的地址列表。我想转换为标题大小写,但保留基本方向的大写,例如 NE、NW、SE、SW。
address <- c("14615 SE CREEKSIDE DRIVE")
stringr::str_to_title(address)
# this returns
14615 Se Creekside Drive
# desired result
14615 SE Creekside Drive
解决方案
尝试:
> gsub("\\b([A-Z])(\\w{2,})", "\\1\\L\\2" , "14615 SE CREEKSIDE DRIVE", perl=true)
[1] "14615 SE Creekside Drive"
正则表达式分解:
\b
匹配单词边界([A-Z])
匹配一个大写字母(\w{2,})
匹配两个以上的单词字符
推荐阅读
- amazon-web-services - AWS Elastic Beanstalk:未知主机
- sql - 尝试更新非事务性表时出现 Hive 错误
- javascript - 如何从 TODO 列表中显示删除按钮
- r - 如何将 SharePoint 列表加载到 R 中的小标题中?
- android - 如果用户隐藏了通知通道,关联的前台服务是否还能成功启动?
- halide - Halide: Var 声明格式
- python-3.x - 为什么 anaconda3 安装似乎以 python2 而不是 python3 结束
- typescript - 如何在 VS 代码中禁用保存时自动加入行?
- python - 解析 XML 时出错:列表索引必须是整数或切片,而不是 Str
- powershell - 当显示名称中有特殊字符时,获取通讯组中所有显示名称的 SMTP 地址