相关疑难解决方法(0)

在字符串中的第一个逗号上拆分

如何使用base在第一个逗号上有效地拆分以下字符串?

x <- "I want to split here, though I don't want to split elsewhere, even here."
strsplit(x, ???)
Run Code Online (Sandbox Code Playgroud)

期望的结果(2个字符串):

[[1]]
[1] "I want to split here"   "though I don't want to split elsewhere, even here."
Run Code Online (Sandbox Code Playgroud)

先感谢您.

编辑:没想到要提这个.这需要能够推广到一个列,像这样的字符串向量,如:

y <- c("Here's comma 1, and 2, see?", "Here's 2nd sting, like it, not a lot.")
Run Code Online (Sandbox Code Playgroud)

结果可以是两列或一个长向量(我可以采用其他所有元素)或每个索引([[n]])具有两个字符串的stings列表.

对于缺乏清晰度表示道歉.

regex r

8
推荐指数
2
解决办法
2417
查看次数

标签 统计

r ×1

regex ×1