数据处理与可视化:从字符串操作到文本挖掘及图形绘制
1. 综合运用 stringr 函数处理字符串
在字符串处理任务中,常常需要结合多个 stringr 函数来实现特定的转换。下面通过一个练习,将 “statistics and machine leaning workshop” 转换为 “stats & ml workshop”。
1.1 具体步骤
- 替换 “and” 为 “&” :
title = "statistics and machine leaning workshop"
title = str_replace(title, pattern = "and", replacement = "&")
title
输出:
"statistics & machine leaning workshop"
这里使用了 str_replace() 函数完成替换。
2. 按 “ & ” 分割字符串 :
a = str_split(title, " & ")
a
输出:
[[1]]
[1] "statistics" "machine leaning work
超级会员免费看
订阅专栏 解锁全文
1139

被折叠的 条评论
为什么被折叠?



