Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/72.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
带有grep的if语句出错_R - Fatal编程技术网

带有grep的if语句出错

带有grep的if语句出错,r,R,运行以下代码: if(grep("sales", resume$jobs$title, ignore.case = TRUE, perl = FALSE, value = FALSE, fixed = FALSE, useBytes = FALSE, invert = FALSE)) {p2_feature = 1} else if(grep("\\$[0-9]+",resume$jobs$text,ignore.case = TRUE, perl = FALSE, value = F

运行以下代码:

if(grep("sales", resume$jobs$title, ignore.case = TRUE, perl = FALSE, value = FALSE,
     fixed = FALSE, useBytes = FALSE, invert = FALSE)) {p2_feature = 1}
else if(grep("\\$[0-9]+",resume$jobs$text,ignore.case = TRUE, perl = FALSE, value = FALSE,
             fixed = FALSE, useBytes = FALSE, invert = FALSE)){p2_feature = 1}
else {p2_feature = 0}
获取错误:

if(grep(“sales”),resume$jobs$title,ignore.case=TRUE,perl)中出错 =FALSE,:参数的长度为零


您必须考虑
grepl
,而不是
grep
grepl
返回逻辑值的向量。
grep
只返回
TRUE
值的索引(如果没有,则长度为0)。只需将
grep
替换为
grepl
,您就会没事。

收到了,谢谢。我使用了长度(grep)>0