#' Check whether two vectors are equal
#'
#' Checks whether all values in two vectors are equal.
#' Returns `NA` if vectors contain NA values.
#'
#' @param vector_one The first vector to be compared.
#' @param vector_two The second vector to be compared.
#' @param na.rm Should missing values be removed? Defaults to `FALSE`.
#'
#' @return Returns TRUE, FALSE, or NA.
#' @importFrom stats na.omit
#' @noRd
#'
#' @examples
#' check_equality(vector_one, vector_two)
check_equality <- function(vector_one, vector_two, na.rm = FALSE) {
# Remove NA values, if na.rm is net to TRUE
if (na.rm) {
vector_one <- na.omit(vector_one)
vector_two <- na.omit(vector_two)
}
# Check whether length of the vectors is the same
if (length(vector_one) != length(vector_two)) {
return(FALSE)
}
# Check whether vectors are equal
length(vector_one == vector_two) == sum(vector_one == vector_two)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.