diff --git a/R/count.R b/R/count.R index 1be07e0..9141020 100644 --- a/R/count.R +++ b/R/count.R @@ -10,7 +10,7 @@ #' #' @examples #' # Count instances of vector elements -#' count(vec = c(1, 1, NA, "a", "a", 1, "a", NA, "x")) +#' count(vec = c(1, 1, NA, "a", 1, "a", NA, "x")) #' count <- function(vec = NULL){ @@ -44,8 +44,10 @@ count <- function(vec = NULL){ # If not NA... } else { + no_empty_vec <- vec[!is.na(vec)] + # Count occurrences - bit_ct <- length(vec[vec == bit]) + bit_ct <- length(no_empty_vec[no_empty_vec == bit]) # Add to dataframe count_df[(count_df$value == bit & !is.na(count_df$value)), ]$count <- bit_ct diff --git a/man/count.Rd b/man/count.Rd index fa81de8..13a0390 100644 --- a/man/count.Rd +++ b/man/count.Rd @@ -17,6 +17,6 @@ Counts the number of occurrences of each element in the provided vector. Countin } \examples{ # Count instances of vector elements -count(vec = c(1, 1, NA, "a", "a", 1, "a", NA, "x")) +count(vec = c(1, 1, NA, "a", 1, "a", NA, "x")) }