Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/74.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R如何拆分字符串_R_Regex_String_Gsub - Fatal编程技术网

R如何拆分字符串

R如何拆分字符串,r,regex,string,gsub,R,Regex,String,Gsub,我有一根像 a <- "Hi. I m cool, but I need help!" 此外,我不想使用额外的软件包。我们可以使用strsplit a1 <- strsplit(a, '\\s|(?=[!,.])\\s*', perl = TRUE)[[1]] a1[nzchar(a1)] #[1] "Hi" "." "I" "m" "cool" "," "but" "I" "need" "help" "!" a1逻辑是什么?在每个非单词

我有一根像

a <- "Hi. I m cool, but I need help!"

此外,我不想使用额外的软件包。

我们可以使用
strsplit

a1 <- strsplit(a, '\\s|(?=[!,.])\\s*', perl = TRUE)[[1]]
a1[nzchar(a1)]
#[1] "Hi"   "."    "I"    "m"    "cool" ","    "but"  "I"    "need" "help" "!"   

a1逻辑是什么?在每个非单词字符处拆分?从“hi…”中得到“hi”的逻辑是什么?你能用下面的代码:
yourString.split(“”)
。我不是R开发人员,但大多数语言都有这样的函数。
a1 <- strsplit(a, '\\s|(?=[!,.])\\s*', perl = TRUE)[[1]]
a1[nzchar(a1)]
#[1] "Hi"   "."    "I"    "m"    "cool" ","    "but"  "I"    "need" "help" "!"