Hi list, Can somebody explain why there are these warning messages?? I just don't get it.? I'm using R 2.15.1 on WinXP. Thanks! Tao> x[1] -2.143510 -1.157450 -1.315581? 1.033562 -1.225440 -1.179909>? ifelse(x>0, log2(x), -log2(-x))[1] -1.099975 -0.210950 -0.395700? 0.047625 -0.293300 -0.238675 Warning messages: 1: In ifelse(x > 0, log2(x), -log2(-x)) : NaNs produced 2: In ifelse(x > 0, log2(x), -log2(-x)) : NaNs produced
Never mind.? I got it.? Thanks! Tao ----- Original Message -----> From: "Shi, Tao" <shidaxia at yahoo.com> > To: "r-help at r-project.org" <r-help at r-project.org> > Cc: > Sent: Monday, October 15, 2012 4:08 PM > Subject: [R] warning message > > Hi list, > > Can somebody explain why there are these warning messages?? I just don't get > it.? I'm using R 2.15.1 on WinXP. > > Thanks! > > Tao > > >> x > [1] -2.143510 -1.157450 -1.315581? 1.033562 -1.225440 -1.179909 > >> ? ifelse(x>0, log2(x), -log2(-x)) > [1] -1.099975 -0.210950 -0.395700? 0.047625 -0.293300 -0.238675 > Warning messages: > 1: In ifelse(x > 0, log2(x), -log2(-x)) : NaNs produced > 2: In ifelse(x > 0, log2(x), -log2(-x)) : NaNs produced > > > ______________________________________________ > 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. >
The second and third arguments to ifelse are evaluated for all elements of x (producing your warnings), then the appropriate elements of each result are combined based on the (logical) values of the first argument to ifelse. On Tue, Oct 16, 2012 at 10:08 AM, Shi, Tao <shidaxia at yahoo.com> wrote:> Hi list, > > Can somebody explain why there are these warning messages? I just don't get it. I'm using R 2.15.1 on WinXP. > > Thanks! > > Tao > > >> x > [1] -2.143510 -1.157450 -1.315581 1.033562 -1.225440 -1.179909 > >> ifelse(x>0, log2(x), -log2(-x)) > [1] -1.099975 -0.210950 -0.395700 0.047625 -0.293300 -0.238675 > Warning messages: > 1: In ifelse(x > 0, log2(x), -log2(-x)) : NaNs produced > 2: In ifelse(x > 0, log2(x), -log2(-x)) : NaNs produced > > > ______________________________________________ > 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.