Skip to content

Commit

Permalink
fix issue with NA in freq_table
Browse files Browse the repository at this point in the history
  • Loading branch information
randrescastaneda committed Jun 11, 2024
1 parent 5446ae9 commit 02cc0b7
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,5 @@ doc
Meta

docs
/doc/
/Meta/
5 changes: 3 additions & 2 deletions R/freq_table.R
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,15 @@ if (getRversion() >= '2.15.1')
#' freq_table(x4, "id1")
freq_table <- function(x,
byvar,
digits = 1) {
digits = 1,
na.rm = FALSE) {

x_name <- as.character(substitute(x))
if (!is.data.frame(x)) {
cli::cli_abort("Argument {.arg x} ({.field {x_name}}) must be a data frame")
}

fq <- qtab(x[[byvar]])
fq <- qtab(x[[byvar]], na.exclude = na.rm)
ft <- data.frame(joyn = names(fq),
n = as.numeric(fq))

Expand Down
4 changes: 2 additions & 2 deletions vignettes/aux-functions.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -103,13 +103,13 @@ Furthermore, `joyn` provides a function that generates simple frequency tables,
# Tabulating frequencies of var `id`
freq_table(x = x1,
byvar = "id")
byvar = "id")[]
# Removing NAs from the calculation
freq_table(x = x1,
byvar = "id",
na.rm = TRUE)
na.rm = TRUE)[]
```

0 comments on commit 02cc0b7

Please sign in to comment.