Add space between two letters in a string in R [duplicate]

不问归期 提交于 2019-12-03 08:42:42

You just need to capture the matches then use the \1 syntax to refer to the captured matches. For example

s = "PleaseAddSpacesBetweenTheseWords"
gsub("([a-z])([A-Z])", "\\1 \\2", s)
# [1] "Please Add Spaces Between These Words"

Of course, this just puts a space between each lower-case/upper-case letter pairings. It doesn't know what a real "word" is.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!