[R] ifelse problem - bug or operator error

Jennifer Sabatier plessthanpointohfive at gmail.com
Fri Aug 24 23:18:48 CEST 2012


Bert,

I will thank you not to condescend to me, as I am too damn old (40) to
be treated that way.  You didn't even offer a solution to my problem.
You only came to chastise me with regards to your assumptions about
me, which is very annoying.

While I am at the beginner level of R, I am not an idiot.  Or an
infant.  I've been a statistician for more than 12 years, mostly
programming in SAS.  I've been moving into R for the past 3 years.

I am EXTENSIVELY familiar with the documentation.  The documentation
is how I've learned to code in R.

I NEVER post to R-help until I've exhausted my own ability to solve
the problem, INCLUDING combing through the documentation.  And looking
at other requests for help to see if the problem has arisen for
someone else.

One of the reason I wait to the last minute to post to R-help is
because it is a very snobby and often unfriendly list, as your comment
illustrates.  You just assumed I hadn't already looked though the
docs.  Nice.

The reality of it is, what Michael pointed out to me wasn't something
I'd discovered in my own search of the docs.  And that, Bert, someone
like me comes to R-help.

Please, Bert, don't we want the whole world to use R?  They won't if
the community is so unwelcoming.

Now, if you have a solution, please post it.  If not, leave off while
I explore Michael's suggestion.

Best,

Jen



On Fri, Aug 24, 2012 at 4:49 PM, Bert Gunter <gunter.berton at gene.com> wrote:
> ... and if Michael is correct, there is a lesson here: Think of how
> much time and aggravation you would have saved yourself if you had
> FIRST made an effort to read the docs. The FAQ's are there for a
> reason. As is An Introduction to R, which also should be read before
> posting on this list.
>
> If Michael is wrong, then the above homily should be amended to:
> If you have not already done so, read the FAQ's and An Introduction to
> R. You will save yourself -- and us -- much time and effort by doing
> so.
>
> Thus endeth the lesson.
>
> -- Bert
>
> On Fri, Aug 24, 2012 at 1:36 PM, R. Michael Weylandt
> <michael.weylandt at gmail.com> wrote:
>> On Fri, Aug 24, 2012 at 3:22 PM, Jennifer Sabatier
>> <plessthanpointohfive at gmail.com> wrote:
>>> Hi R-Helpers,
>>>
>>> I don't think I need to post a dataset for this question but if I do, I
>>> can.  Anyway, I am having a lot of trouble with the ifelse command.
>>>
>> You probably should have: dput() makes it super easy as well.
>>
>>> Here is my code:
>>>
>>>
>>> vn$PM.DIST_flag <- ifelse( (vn$PM.EXP > 0.0) & (vn$PM.DIST.TOT != 1.0), 1,
>>> 0 )
>>>
>>>
>>> And here is my output that doesn't make ANY sense:
>>>
>>>   PM.EXP PM.DIST.TOT PM.DIST_flag  0 0 0  0 0 0  0 0 0  177502 1 0  31403 1
>>> 0  0 0 0  1100549 1 0  38762 1 0  0 0 0  20025 1 0  0 0 0  13742 1 0  0 0 0
>>> 83078 1 0  0 0 0  0 0 0  0 0 0  0 0 0  0 0 0  0 0 0  0 0 0  0 0 0  0 0 0
>>> 165114 1 0  0 0 0  417313 1 0  3546 1 0  4613 1 0  225460 1 0  6417 1 1  23
>>> 1 0  3402 1 0  8504 1 1  8552 1 0  9723 1 0  37273 1 1  396 1 0  1478 1 0
>>> 2074 1 0  12220 1 1  97691 2 1  0 0 0  33993 2 1
>>
>> Indeed it makes no sense to me either because you sent HTML email
>> which got mangled by the server.
>>
>>>
>>> As you can see, there are many instances where PM.EXP > 0 and PM.DIST.TOT =
>>> 1 yet PM.DIST_flag = 1 and it should be 0.  It should only flag in cases
>>> such as the last line of data.
>>>
>>> WWHHHYYYYYYYY???? Why why why why why why why? Why?
>>>
>>> (Sorry, I've been trying to figure this out for hours and I've devolved to
>>> mumbling in corners and banging my head against the table)
>>>
>>> What in the world am I doing wrong?  Or is ifelse not the right function?
>>
>> First guess.... standard problems with equality of floating point
>> numbers. (See R FAQ 7.31 for the details)
>>
>> You probably want to change
>>
>> x == 1
>>
>> to
>>
>> abs(x - 1) < 1e-05
>>
>> or something similar.
>>
>> Cheers,
>> Michael
>>
>>>
>>> Best,
>>>
>>> Jen
>>>
>>>         [[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.
>>
>> ______________________________________________
>> 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.
>
>
>
> --
>
> Bert Gunter
> Genentech Nonclinical Biostatistics
>
> Internal Contact Info:
> Phone: 467-7374
> Website:
> http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm




More information about the R-help mailing list