Learn R Programming

mark (version 0.8.1)

remove_na: Remove NA

Description

Remove NAs from a vector

Usage

remove_na(x)

# S3 method for default remove_na(x)

# S3 method for list remove_na(x)

# S3 method for factor remove_na(x)

# S3 method for fact remove_na(x)

Value

x without values where is.na(x) is TRUE

For factors, a new factor (ordered if is.ordered(x))

Arguments

x

A vector of values

Details

remove_na.factor will remove NA values as identified by the levels() or by the integer value of the level. factors are recreated with all NA values and, if present, the NA level removed.

Examples

Run this code
remove_na(c(4, 1, 2, NA, 4, NA, 3, 2))

# removes based on levels
remove_na(fact(c("b", NA, "a", "c")))

# removes based on values
x <- as_ordered(c("b", "d", "a", "c"))
x[2:3] <- NA
str(remove_na(x))

Run the code above in your browser using DataLab