Pmin gives the wrong answer

pmin does not return the corresponding output in the following example.

eps <- 1e-16
x <- structure(list(X = c(0.219801587301587, 0.340792857142857, 0.398129365079365, 
                      1, 1, 0.853353968253968, 0.930726984126984, 0.980263131313131, 
                      0.968269047619047, 0.953053336369513, 1, 1, 1, 0.951969003219003, 
                      0.91514335177894, 0.884824997224998, 0.884824997224998, 0.884824997224998 )), row.names = c(NA, 18L), class = "data.frame", .Names = "X")

pmin(x, 1 - eps)

The function incorrectly returns NAwhere the value xis 1. If this is reported as an error?

+6
source share
1 answer

So, I realized that this is because it xis data.frame, and pmin is expecting a vector. So, the following works just fine:

pmin(x[,1], 1 - eps)

But I wanted to understand why it did not work for data.frame. Therefore, passing through the code for pmin, the line of violation is as follows:

mmm[change] <- each[change]

each (1 - eps ), change - , , each[1], NA. , x - , :

  if (all(vapply(elts, function(x) is.atomic(x) && !is.object(x), NA))) {
      mmm <- .Internal(pmin(na.rm, ...))
      mostattributes(mmm) <- attributes(elts[[1L]])
   }

, -, , pmin , , data.frame, .

+5

All Articles