[R] ifelse

R. Michael Weylandt michael.weylandt at gmail.com
Thu Feb 9 17:46:39 CET 2012


cat() returns a null value so it's problematic inside ifelse. Here you
probably need a regular if statement:

if(all(list %in% c(1, 10, 100))) cat("YES\n") else cat("NO\n") # The
== TRUE is redundant.

Michael

On Thu, Feb 9, 2012 at 11:37 AM, Arnaud Gaboury
<arnaud.gaboury at a2ct2.com> wrote:
> Hello,
>
> I need to print a screen message after a test.
>
>>list<-c("10","1","100","10")
>>ifelse(all(list %in% c(1,10,100)==TRUE),cat("YES\n"),cat("NO\n"))
> YES
> Error in ifelse(all(l %in% c(1, 10, 100) == TRUE), cat("YES\n"), cat("NO\n")) :
>  replacement has length zero
>
>
> I have the correct answer, YES, but with an Error.
>
> Why?
>
> TY for any help
>
>
> Arnaud Gaboury
>
> A2CT2 Ltd.
>
> ______________________________________________
> R-help at 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
> and provide commented, minimal, self-contained, reproducible code.



More information about the R-help mailing list