[R] case conversion and/or string comparison

David Barron
Fri, 16 Nov 2001 11:56:48 -0000

That's because grep returns the *indices* of the elements of x that yielded
a match.  If there are no matches, then grep returns a (numeric) vector of
length 0.  A quick and dirty way of achieving what you want would therefore
be to test the length of the vector returned, eg,

if (length(grep("HGT","tem",ignore.case=T))==0)
print("hi")

I'm sure there is a better way, though!

Dave