tests/product.R

library("matrixStats")

# Empty vector
x <- integer(0)
y <- prod(x, na.rm=TRUE)
print(y)
z <- product(x, na.rm=TRUE)
print(z)
stopifnot(all.equal(z, y))

# Test missing values
x <- c(1,NA,NaN,2)
y <- prod(x, na.rm=TRUE)
print(y)
z <- product(x, na.rm=TRUE)
print(z)
stopifnot(all.equal(z, y))

x <- c(1,NA,NaN,2)
y <- prod(x, na.rm=FALSE)
print(y)
z <- product(x, na.rm=FALSE)
print(z)
stopifnot(all(is.na(z), is.na(y)))

x <- c(1,NaN,2)
y <- prod(x, na.rm=FALSE)
print(y)
stopifnot(is.na(y))
z <- product(x, na.rm=FALSE)
print(z)
stopifnot(is.na(z))

Try the matrixStats package in your browser

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

matrixStats documentation built on May 2, 2019, 4:52 p.m.