我问的是一个允许轻松做某事的功能
grepl(c("word1","word2"), vector_of_strings)
我的意思是,做类似的事情:"在这个载体的某个位置有这些词?" TRUE/FALSE
由于
答案 0 :(得分:0)
我想你想要像android:layout_gravity="center"
stringr::str_detect
答案 1 :(得分:0)
可能是这样的:
vector_of_strings <- c(
'here is word1',
'and word2 plus word4',
'but word3 and word1 are here'
)
sapply(c("word1", "word2", "word3", "word4"), function(x){
grepl(x, vector_of_strings)
})
## word1 word2 word3 word4
## [1,] TRUE FALSE FALSE FALSE
## [2,] FALSE TRUE FALSE TRUE
## [3,] TRUE FALSE TRUE FALSE
其中返回矩阵的每一行对应于字符串向量中的元素。