Java Mailing List Archive

http://www.r-help.com/

Home » R Help for Statistical Computing »

Re: [R] argument is of length zero

jim holtman

2010-03-11

Replies: Find Java Web Hosting

Author LoginPost Reply
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@(protected):

> 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@(protected)
> 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]]

______________________________________________
R-help@(protected)
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
©2008 r-help.com - Jax Systems, LLC, U.S.A.