带有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