Re: [Rd] mean(x) != mean(rev(x)) different with x <- c(NA, NaN) for some builds

2017-04-01 Thread Hervé Pagès
On 03/31/2017 10:14 PM, Prof Brian Ripley wrote: From ?NA Numerical computations using ‘NA’ will normally result in ‘NA’: a possible exception is where ‘NaN’ is also involved, in which case either might result. and ?NaN Computations involving ‘NaN’ will return ‘NaN’ or

Re: [Rd] mean(x) != mean(rev(x)) different with x <- c(NA, NaN) for some builds

2017-04-01 Thread Henrik Bengtsson
Although help("is.nan") says: "Computations involving NaN will return NaN or perhaps NA: ..." it might not be obvious that this is also why one may get: > mean(c(-Inf, +Inf, NA)) [1] NaN > mean(c(-Inf, NA, +Inf)) [1] NA This is because internally the intermediate sum +Inf + -Inf is NaN in

Re: [Rd] mean(x) != mean(rev(x)) different with x <- c(NA, NaN) for some builds

2017-03-31 Thread Henrik Bengtsson
On Fri, Mar 31, 2017 at 10:14 PM, Prof Brian Ripley wrote: > From ?NA > > Numerical computations using ‘NA’ will normally result in ‘NA’: a > possible exception is where ‘NaN’ is also involved, in which case > either might result. > > and ?NaN > >

Re: [Rd] mean(x) != mean(rev(x)) different with x <- c(NA, NaN) for some builds

2017-03-31 Thread Prof Brian Ripley
From ?NA Numerical computations using ‘NA’ will normally result in ‘NA’: a possible exception is where ‘NaN’ is also involved, in which case either might result. and ?NaN Computations involving ‘NaN’ will return ‘NaN’ or perhaps ‘NA’: which of those two is not

[Rd] mean(x) != mean(rev(x)) different with x <- c(NA, NaN) for some builds

2017-03-31 Thread Henrik Bengtsson
In R 3.3.3, I observe the following on Ubuntu 16.04 (when building from source as well as for the sudo apt r-base build): > x <- c(NA, NaN) > mean(x) [1] NA > mean(rev(x)) [1] NaN > rowMeans(matrix(x, nrow = 1, ncol = 2)) [1] NA > rowMeans(matrix(rev(x), nrow = 1, ncol = 2)) [1] NaN >