R/NAsum.R

Defines functions NASum

Documented in NASum

#' Sum the number of NAs in row.
#'
#' `NASum` Takes a Data.frame and calculate the number of NAs
#' for a given variable.
#'
#' @param df The data frame/tibble where the variable you intrested have NA.
#' @param Vars The variables (columns) you want to count the NAs from.
#' @return The number of missing variables as a new column to the Orignical data frame
#' @examples
#' ###With one variable
#' df<-df %>%
#' mutate(Valid=NASum(df, c("var1")))
#'
#' ###With four variables
#' df<-df %>%
#' mutate(Valid=NASum(df, c("var1", "var2","var3", "var4")))

NASum <- function(df, Vars)
{
  Temp <- rowSums(is.na(df[,Vars]))
  return(Temp)
}
AmirDJV/UsefulFunctions documentation built on Nov. 18, 2017, 5:10 a.m.