From ml-it-r-devel at epigenomics.com  Thu Apr 26 17:53:09 2007
From: ml-it-r-devel at epigenomics.com (ml-it-r-devel at epigenomics.com)
Date: Thu, 26 Apr 2007 17:53:09 +0200
Subject: [Rd] ifelse behaviour
In-Reply-To: <4630B19B.1070103@stats.uwo.ca>
References: <f0qasl$j79$1@perl.epigenomics.epi> <4630B19B.1070103@stats.uwo.ca>
Message-ID: <4630CAE5.5000904@epigenomics.com>

Duncan Murdoch wrote:
> On 4/26/2007 9:53 AM, ml-it-r-devel at epigenomics.com wrote:
>> Hi!
>>
>> I'm puzzled by the return value of ifelse
>>
>> consider
>>
>> x<-integer(0)
>> ifelse(is(x, "character"), paste(x), x)
>> [1] NA
> 
> The test evaluates to a length 1 logical vector containing FALSE.  So 
> ifelse() tries to return the first entry of x.  But x[1] doesn't exist, 
> so it evaluates to NA, and that's what ifelse() returns.

Thank you for the explanation!

Regards,

   Matthias

>>
>> whereas
>> if (is(x, "character")) return(paste(x)) else x
>> [1] integer(0)
> 
> This is quite different. It says to return the expression in the else 
> clause, which is x.
>>
>> or
>> x<-integer(1)
>> ifelse(is(x, "character"), paste(x), x)
>> [1] 0
>>
>> work as I had anticipated. Is this correct behaviour?
> 
> Yes, this is correct.
> 
> Duncan Murdoch
> 


-- 
Matthias Burger                     Project Manager/ Biostatistician
Epigenomics AG    Kleine Praesidentenstr. 1    10178 Berlin, Germany
phone:+49-30-24345-371                          fax:+49-30-24345-555
http://www.epigenomics.com           matthias.burger at epigenomics.com
--
Epigenomics AG Berlin           Amtsgericht Charlottenburg HRB 75861
Vorstand:   Geert Nygaard (CEO/Vorsitzender),  Dr. Kurt Berlin (CSO)
               Oliver Schacht PhD (CFO),  Christian Piepenbrock (COO)
Aufsichtsrat:   Prof. Dr. Dr. hc. Rolf Krebs (Chairman/Vorsitzender)



[Rd] ifelse behaviour
ml-it-r-devel at epigenomics.com