Learn R Programming

janitor (version 0.2.1)

convert_to_NA: Convert string values to true NA values.

Description

Converts instances of user-specified strings into NA. Can operate on either a single vector or an entire data.frame.

Usage

convert_to_NA(dat, strings)

Arguments

dat
vector or data.frame to operate on.
strings
character vector of strings to convert.

Value

Returns a cleaned object. Can be a vector, data.frame, or tibble::tbl_df depending on the provided input.

Examples

Run this code
convert_to_NA(mtcars, "4") # a silly example;
# mtcars has no string NA values, but this will convert 4s to NA

# a more typical call would be (not run):
# convert_to_NA(my_df, c("NA", "#N/A", "N/A", "n/a", "#NAME?"))
# catches common strings that should be NA

convert_to_NA(letters, c("b", "d"))

Run the code above in your browser using DataLab