Skip to content

Commit

Permalink
Fixed an issue with count treatment of non-NA elements (only presen…
Browse files Browse the repository at this point in the history
…t when some elements *are* NA)
  • Loading branch information
njlyon0 committed May 15, 2024
1 parent 8ad6fbc commit 72f8452
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
6 changes: 4 additions & 2 deletions R/count.R
Original file line number Diff line number Diff line change
Expand Up @@ -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){

Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion man/count.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 72f8452

Please sign in to comment.