#' Is the number even?
#' @importFrom assertthat assert_that
#' @param num ; The number to check if it is even
#' @return logical ; True if 'num' is even
#' @export
my.is.even <- function(num) {
assert_that(is.numeric(num))
return((num%%2) == 0)
}
#' Is the number odd?
#' @importFrom assertthat assert_that
#' @param num ; The number to check if it is odd
#' @return logical ; True if 'num' is odd
#' @export
my.is.odd <- function(num) {
assert_that(is.numeric(num))
return(!my.is.even(num))
}
#' Calculate the minimun number
#' @importFrom assertthat assert_that
#' @param src.vector ; A numeric vector to calculate minimum value over.
#' @return numeric ; The Minimum Value of 'src.vector'.
#' @export
my.min <- function(src.vector) {
assert_that(is.numeric(src.vector))
assert_that(is.vector(src.vector))
return(sort(src.vector)[1])
}
#' Calculate the maximun number
#' @importFrom assertthat assert_that
#' @param src.vector ; A numeric vector to calculate maximum value over.
#' @return numeric ; The Maximum Value of 'src.vector'.
#' @export
my.max <- function(src.vector) {
assert_that(is.numeric(src.vector))
assert_that(is.vector(src.vector))
return(sort(src.vector, decreasing = TRUE)[1])
}
#' Calculate the product of every element of a numeric vector.
#' @importFrom assertthat assert_that
#' @param src.vector ; A numeric vector to calculate maximum value over.
#' @return numeric ; The Product of every element of 'src.vector'.
#' @export
my.product <- function(src.vector) {
assert_that(is.numeric(src.vector))
assert_that(is.vector(src.vector))
dst <- 1
for (elem in src.vector) dst <- dst * elem
return(dst)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.