-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from metrumresearchgroup/fix-nasum
Fix nasum
- Loading branch information
Showing
6 changed files
with
26 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,7 +32,8 @@ Imports: | |
hms, | ||
lubridate, | ||
purrr, | ||
readr | ||
readr, | ||
tidyr | ||
Suggests: | ||
sessioninfo, | ||
knitr, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,25 @@ | ||
#' Count Number of \code{NA} Values in List Items | ||
#' Display a count of NAs by column in a data.frame | ||
#' | ||
#' @description | ||
#' \code{nasum} Count the number of \code{NA} values in each element of a list-like object. | ||
#' | ||
#' @param x list of vector-like objects; e.g. a data frame | ||
#' @param simplify logical: coerce to vector result if possible | ||
#' | ||
#' @usage nasum(x,simplify=TRUE) | ||
#' @param .df the count of NAs will be calculated for each column in this data | ||
#' set, with any grouping variables retained | ||
#' | ||
#' @details | ||
#' Arguments are passed to \code{simplify}, along with a function | ||
#' that sums instances of \code{NA}. | ||
#' | ||
#' @author Natalie Hsiang | ||
#' @author Tim Waterhouse | ||
#' | ||
#' @examples | ||
#' nasum(Theoph) | ||
#' | ||
#' @export | ||
nasum <- function(x, simplify=TRUE)sapply(x,FUN=function(y)sum(is.na(y)),simplify=simplify) | ||
nasum <- function(.df) { | ||
.df %>% | ||
dplyr::summarize(dplyr::across(dplyr::everything(), ~ sum(is.na(.))), .groups = "keep") %>% | ||
tidyr::pivot_longer(-dplyr::group_cols(), values_to = "n_NA") %>% | ||
dplyr::ungroup() %>% | ||
dplyr::filter(n_NA > 0) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters