R中的哪个函数有pmatch等价物吗?

R中的哪个函数有pmatch等价物吗?,r,matrix,R,Matrix,我使用以下代码获取R中以下矩阵中某些匹配项的索引: [,1][,2] [1,][t2”“t2” [2,][t5”“t5” [3,][t7”“t7” [4,][t10”“t10” [5,][t9”“t9” [6,]“t4”和“t4” [7,][t8”“t8” [8,][t6”“t6” [9,][t3”“t3” [10,]t1“t1” searchstring您可以尝试这样做,它将搜索字符串的每个成员与列匹配,这样您就可以跟踪哪个元素与where匹配。如果没有必要,您可以取消列出结果 lappy(

我使用以下代码获取R中以下矩阵中某些匹配项的索引:

[,1][,2]
[1,][t2”“t2”
[2,][t5”“t5”
[3,][t7”“t7”
[4,][t10”“t10”
[5,][t9”“t9”
[6,]“t4”和“t4”
[7,][t8”“t8”
[8,][t6”“t6”
[9,][t3”“t3”
[10,]t1“t1”

searchstring您可以尝试这样做,它将搜索字符串的每个成员与列匹配,这样您就可以跟踪哪个元素与where匹配。如果没有必要,您可以
取消列出结果

lappy(搜索字符串,函数(x){
其中(!is.na(match(substr(association[,1],1,nchar(x)),x)))
#> [[1]]
#> [1]  4 10
#> 
#> [[2]]
#> [1] 1

数据

set.seed(3295269)
协会[,1][,2]
#>[1,][t2”“t2”
#>[2,][t5”“t5”
#>[3,][t7”“t7”
#>[4,][t10”“t10”
#>[5,][t9”“t9”
#>[6,]“t4”和“t4”
#>[7,][t8”“t8”
#>[8,][t6”“t6”
#>[9,][t3”“t3”
#>[10,]t1“t1”

searchstring您可以尝试这样做,它将搜索字符串的每个成员与列相匹配,这样您就可以跟踪哪个元素与where相匹配。如果没有必要,您可以
取消列出结果

lappy(搜索字符串,函数(x){
其中(!is.na(match(substr(association[,1],1,nchar(x)),x)))
#> [[1]]
#> [1]  4 10
#> 
#> [[2]]
#> [1] 1

数据

set.seed(3295269)
协会[,1][,2]
#>[1,][t2”“t2”
#>[2,][t5”“t5”
#>[3,][t7”“t7”
#>[4,][t10”“t10”
#>[5,][t9”“t9”
#>[6,]“t4”和“t4”
#>[7,][t8”“t8”
#>[8,][t6”“t6”
#>[9,][t3”“t3”
#>[10,]t1“t1”

searchstring也许你可以试试
grep

> lapply(paste0("^", searchstring), grep, x = association[, 1])
[[1]]
[1]  4 10

[[2]]
[1] 1
startsWith
+
unstack

> unstack(as.data.frame(which(sapply(searchstring, startsWith, x = association[, 1]), arr.ind = TRUE)))
$`1`
[1]  4 10

$`2`
[1] 1

也许你可以试试
grep

> lapply(paste0("^", searchstring), grep, x = association[, 1])
[[1]]
[1]  4 10

[[2]]
[1] 1
startsWith
+
unstack

> unstack(as.data.frame(which(sapply(searchstring, startsWith, x = association[, 1]), arr.ind = TRUE)))
$`1`
[1]  4 10

$`2`
[1] 1

searchstring始终是一个值,还是希望它在多个值上工作?例如:
它(Reduce(`|`,lappy(searchstring,grepl,x=association[,1]))
或者类似的东西可以一起做所有的事情。这很有效。非常感谢。searchstring始终是一个值,还是希望它在多个值上工作?例如:
它(Reduce(`|`,lappy(searchstring,grepl,x=association[,1]))
或者类似的东西可以一起做所有的事情。这很有效。非常感谢。