R/prodskip1.r

Defines functions prodskip1

# [prod_{j != i} x_j]_{i = 1 à n}
prodskip1 <- function(x) {
  I <- (x == 0)
  Z <- sum(I)
  if(Z == 0L) {
    x <- prod(x)/x
  } else if(Z == 1L) {
    x[I] <- prod(x[!I])
    x[!I] <- 0
  } else {
    x[] <- 0
  }
  x
}

Try the salad package in your browser

Any scripts or data that you put into this service are public.

salad documentation built on April 4, 2025, 1:06 a.m.