初始向量是
"WhiteRiver" "microProcess" "PartsUnknown" "RedSox"
如何将其拆分为
White" "River" "micro" "Process" "Parts" "Unknown" "Red" "Sox"
规则是在大小写之间分开。
答案 0 :(得分:5)
如果v1
是向量
unlist(strsplit(v1, "(?<=[a-z])(?=[A-Z])", perl=TRUE))
#[1] "White" "River" "micro" "Process" "Parts" "Unknown" "Red"
#[8] "Sox"
小写字母 (?<=[a-z])
后悔
(?=[A-Z])
预测大写字母
答案 1 :(得分:0)
使用像@akrun这样的v1
:
unlist(strsplit(sub("([a-z])([A-Z])", "\\1,\\2", v1), ","))
#[1] "White" "River" "micro" "Process" "Parts" "Unknown" "Red" "Sox"
如果要分割的字数超过两个,请使用gsub
代替sub