![](/img/trans.png)
[英]Using strsplit when required split character vector is not consistent for all observations in variable (R)
[英]strsplit does not split for all elements of character vector provided to parameter “split”
strsplit
函数的R文档声明参数split
“如果拆分长度大于1,则沿x重新循环”。
我认为如果我使用以下代码
strsplit(x = "Whatever will be will be", split = c("ever", "be"))
...,我将x
分为“What”,“will”和“will be”。 这不会发生。 输出是“什么”和“将会是”。
我误解了文档吗? 另外,我怎样才能得到我想要的结果?
如果x
有多个参数,则split中的参数将被回收:
strsplit(x = c("Whatever will be will be","Whatever will be will be"),
split = c("ever", "be"))
[[1]]
[1] "What" " will be will be"
[[2]]
[1] "Whatever will " " will "
我怀疑你期望的行为是通过|
来实现的 :
strsplit(x = "Whatever will be will be", split = c("ever|be"))
[[1]]
[1] "What" " will " " will "
split
在x的元素之间循环,因此split的第一个元素应用于x的第一个元素,第二个元素应用于第二个元素等等。因此,例如:
strsplit(x = c("Whatever will be will be", "Whatever will be will be"), split = c("ever", "be"))
[[1]]
[1] "What" " will be will be"
[[2]]
[1] "Whatever will " " will "
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.