Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/71.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/string/5.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_String - Fatal编程技术网

R 获取给定字符串中的子字符串位置

R 获取给定字符串中的子字符串位置,r,string,R,String,考虑字符串: a <- "this is a string" 但似乎没有给出位置 是否有一个函数可以告诉我任何子字符串的位置 getLoction(a, "t") ## 1 12 getLoction(a, "this") ## 1 给你,我偏爱stringr软件包: library(stringr) a <- "this is a string" str_locate(a,"t") str_locate(a,"this") str_locate_all(a,"t") lib

考虑字符串:

a <- "this is a string"
但似乎没有给出位置

是否有一个函数可以告诉我任何子字符串的位置

getLoction(a, "t")
## 1 12

getLoction(a, "this")
## 1

给你,我偏爱stringr软件包:

library(stringr)
a <- "this is a string"
str_locate(a,"t")
str_locate(a,"this")
str_locate_all(a,"t")
library(stringr)
a <- "this is a string"
str_locate(a,"t")
str_locate(a,"this")
str_locate_all(a,"t")
> str_locate(a,"t")
     start end
[1,]     1   1
> str_locate(a,"this")
     start end
[1,]     1   4
> str_locate_all(a,"t")
[[1]]
     start end
[1,]     1   1
[2,]    12  12