[R] Problematic If-Else statement

MacQueen, Don macqueen1 at llnl.gov
Sat Sep 17 01:53:38 CEST 2011


It's probably not a sensible thing to do, but I'm going to guess.

With a name like "days_to_tumor_recurrence", I might expect numeric
(integer) values. But "null" and numeric don't mix.

as.numeric(c('24','null',23')) will return 24, NA, 23.

There may have been such a conversion in the preparation of the data.

-Don

-- 
Don MacQueen

Lawrence Livermore National Laboratory
7000 East Ave., L-627
Livermore, CA 94550
925-423-1062





On 9/16/11 8:54 AM, "David Winsemius" <dwinsemius at comcast.net> wrote:

>
>On Sep 16, 2011, at 11:49 AM, Ben Ganzfried wrote:
>
>> Thanks David.  That works perfectly! Although, I'm still not sure I
>> understand entirely why the input file says the character value
>> "null" and yet, it actually is NA...
>
>Unless you show us the file as it would appear in a text editor, and
>how you brought it into R, and then processed it,  we will not have
>any chance of commenting sensibly.
>
>-- 
>David.
>
>>
>> On Fri, Sep 16, 2011 at 11:35 AM, David Winsemius
>><dwinsemius at comcast.net
>> > wrote:
>>
>> On Sep 16, 2011, at 11:08 AM, David Winsemius wrote:
>>
>>
>> On Sep 16, 2011, at 10:36 AM, Ben Ganzfried wrote:
>>
>> Hi guys,
>>
>> snipped
>>
>>
>> Second, I changed the first line of my code to:
>> tmp <-
>> ifelse(uncurated
>> $days_to_tumor_recurrence==NA,"norecurrence","recurrence")
>>
>> I do not know why your original did not succeed but this code should
>> have been written:
>>
>> tmp <-
>> ifelse(is,na(uncurated
>> $days_to_tumor_recurrence),"norecurrence","recurrence")
>>          ^.^
>>
>> Except that should have been a period.
>>
>> --
>>
>> David Winsemius, MD
>> West Hartford, CT
>>
>>
>
>David Winsemius, MD
>West Hartford, CT
>
>
>	[[alternative HTML version deleted]]
>
>______________________________________________
>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