用 R 中大于 1 的空格分割 strsplit [英] strsplit by spaces greater than one in R

查看:27
本文介绍了用 R 中大于 1 的空格分割 strsplit的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

给定一个字符串,

mystr = "Average student score       88"

如果有超过 1 个空格,我希望拆分.我希望获得以下内容:

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

"Average student score" "88"

我搜索到\s+"会被任意数量的空格分割.

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

strsplit(mystr, "\\s+")

但这不是我想要的.strsplit 中是否有任何选项可以根据一定数量的空格(比如空格 = k)或空格规则(比如空格 > 1)拆分字符串?

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)?

推荐答案

您可以通过重复量词来指定.

You may specify it through a repetition quantifier.

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

\\s{2,} 正则表达式应匹配两个或多个空格.

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

这篇关于用 R 中大于 1 的空格分割 strsplit的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆