标签:pre span int require round 天气 size 包含 else
#检测一个字符串中,是否包含某个子串,是返回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):为总共包含这个词的元素的个数
标签:pre span int require round 天气 size 包含 else
原文地址:https://www.cnblogs.com/li-20151130/p/9038876.html