Skip to content
Prev 304105 / 398513 Next

ifelse problem - bug or operator error

I see that you got other responses while I was composing an answer.
Your 'example.csv' did come through for me, but I still can't
replicate your PM.DIST_flag variable. Specifically, observations
30, 33, 36 and 40 are wrong.

I agree with Rui, that there's something else going on. The data
you've sent can't be the data that yielded the 'flag' variable
or you didn't use the ifelse() function in the way that you've
shown.

I would start with a clean R session and I would use the 'convert
logical to numeric' idea (or keep a logical rather than numeric
flag):

   vn <- transform(vn,
           my_flag = ( (PM.EXP > 0) & (PM.DIST.TOT != 1) ) * 1 )

It looks as though your PM.DIST.TOT variable is meant to be
integer. If so, you might want to ensure that it is that type.
Otherwise, you might want to use Michael's suggestion of using
abs(... - 1) < 1e-05.

Peter Ehlers
On 2012-08-24 14:56, Jennifer Sabatier wrote: