Skip to content

ifelse

4 messages · R. Michael Weylandt, Arnaud Gaboury, David Winsemius

#
Hello,

I need to print a screen message after a test.
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.
#
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:
#
TY much.

Works for me.

Arnaud Gaboury
?
A2CT2 Ltd.


-----Original Message-----
From: R. Michael Weylandt [mailto:michael.weylandt at gmail.com] 
Sent: jeudi 9 f?vrier 2012 17:47
To: Arnaud Gaboury
Cc: r-help at r-project.org
Subject: Re: [R] ifelse

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:
#
On Feb 9, 2012, at 11:37 AM, Arnaud Gaboury wrote:

            
cat() returns NULL. Why ar enou not just returning the strings  
themselves or if you want to see the results as well as assign, then  
use print() which does return its arguments.
David Winsemius, MD
West Hartford, CT