#检测一个字符串中,是否包含某个子串,是返回T,否返回Frequire(stringr)

require(stringr)
test <- c("这里有天气热敏感冒","好天气","感冒了,也要加油","感?冒","","不是","感冒?不是!")
str_detect(test,"感冒")

num_dec <- 0;loops <-1
while(loops <= length(test)){
  if(is.na(test[loops])){
    loops = loops + 1
  }else{
    if(str_detect(test[loops],"感冒")){
      num_dec = num_dec + 1
      print(loops) 
      loops = loops + 1
    }else{loops = loops + 1}
  }
}
print(num_dec)

  

  输出结果有:print(loops)为包含“感冒”这个词的元素 的坐标。print(num_dec):为总共包含这个词的元素的个数

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-11-13
  • 2022-12-23
  • 2022-12-23
  • 2021-09-05
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-05-30
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案