Reputation: 193
I want to use the return value of function grep, I just want to judge whether the var_name has the var I want:
> res<-grep(y,var_name,fixed=FALSE)
> res
integer(0)
> (res==integer(0))
logical(0)
> (res==NULL)
logical(0)
But it is always logical(0), is there any way I can solve this problem
Upvotes: 0
Views: 1150
Reputation: 31181
You can try:
if(length(res)==0)
{
# some code
}
Or directly:
grepl(y, var_name)
Example:
y='dog'
var_name='I am a cat'
# grepl(y, var_name)
#[1] FALSE
Upvotes: 2