[R] Bug in ifelse

Daniel Malter daniel at umd.edu
Thu Oct 9 23:33:16 CEST 2008

Hi all, I am quite sure it's not a bug, but I am going nuts about this. I do
not possibly understand why I get different results for b1 and b2 as shown



z=y[y<max(x)] ##all Ys smaller than the maximum of X

a=ifelse(length(z)==0,NA,max(z)) ##assign NA if length of z is zero, take
the max of z otherwise

b1=ifelse(is.numeric(a)==T,x[x>a],x) ##if a is numeric, assign all x that
are greater than a; otherwise assign the entire x

b2=x[x>a] ## assign all x greater than a

b1 and b2 should be equal as I see it. Anybody who can explain why they are
not makes my day, especially the one who can tell me how I can get b1 equal
to b2 (without sacrificing the ifelse condition).

Thanks much,

cuncta stricte discussurus

More information about the R-help mailing list