strsplit by spaces greater than one in R

天涯浪子 提交于 2019-12-20 02:58:17

问题


Given a string,

mystr = "Average student score       88"

I wish to split if there are more than 1 space. I wish to obtain the following:

"Average student score" "88"

I searched that "\s+" will split by any number of spaces.

strsplit(mystr, "\\s+")

But this is not what I want. Is there any option within strsplit that can split strings based on a certain number of spaces (say space = k) or a rule on spaces (say space > 1)?


回答1:


You may specify it through a repetition quantifier.

strsplit(mystr, "\\s{2,}")

\\s{2,} regex should match two or more spaces.



来源:https://stackoverflow.com/questions/34916149/strsplit-by-spaces-greater-than-one-in-r

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