Test for the condition you are looking for. If the grep does not match, it
returns a vector of length zero
> a='hello world'
> if (length(grep('hellow',a)) != 0) {
+ print("wow")
+ } else {
+ print("wow2")
+ }
[1] "wow2">
On Thu, Mar 11, 2010 at 6:59 PM, Dan Joo <djoo@agraquest.com> wrote:
> I am new to R, so I beg your indulgence.
> > a='hello world'
> > if (grep('hellow',a)) {
> print("wow")
> } else {
> print("wow2")
> }
> Error in if (grep("hellow", a)) { : argument is of length zero
>
> What is the proper syntax to ensure that "wow2" gets printed?
>
> Thank you for your help!
>
> Dan
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
>
http://www.R-project.org/posting-guide.html<http://www.r-project.org/posting-guide.html>
> and provide commented, minimal, self-contained, reproducible code.
>
--
Jim Holtman
Cincinnati, OH
+1 513 646 9390
What is the problem that you are trying to solve?
[[alternative HTML version deleted]]