条件性地在空间分割字符串

时间:2014-08-03 16:22:16

标签: r

我的输入向量是

'salesman snow "rain check" "Radio shack"'

我正在寻找的答案是

"salesman"    "snow"        "rain check"  "Radio shack"

尝试

  strsplit(vector, " ")

1 个答案:

答案 0 :(得分:0)

喜欢这个?

> gsub('"', '', regmatches(vector, gregexpr('"[^\\"]*"|(\\S+)',  vector))[[1]])
[1] "salesman"    "snow"        "rain check"  "Radio shack"