Learn R Programming

missMethods (version 0.4.0)

count_NA: Count the number of NAs

Description

Count the number of NA values in a vector, matrix or data frame

Usage

count_NA(x, type = "default")

Value

The number of missing values.

Arguments

x

a vector, matrix or data frame, in which NA values are counted

type

How to count the NA values. Possible choices:

  • "default": If x is a matrix or a data frame, the number of missing values per column is returned. If x is something else, the total number of missing values in x is returned.

  • "all": The number of all missing values in x is returned.

  • "cols": The number of missing values per column is returned.

  • "rows": The number of missing values per row is returned.

Examples

Run this code
count_NA(c(1, NA, 3, NA, 5, NA))
test_df <- data.frame(X1 = rep(c(1, NA), 5), X2 = c(1:9, NA))
count_NA(test_df)
count_NA(test_df, "cols") # the default
count_NA(test_df, "rows")
count_NA(test_df, "all")

Run the code above in your browser using DataLab