Learn R Programming

datawizard (version 0.4.0)

replace_nan_inf: Convert infinite or NaN values into NA

Description

Replaces all infinite (Inf and -Inf) or NaN values with NA.

Usage

replace_nan_inf(data)

Arguments

data

A vector or a data frame.

Value

Data with Inf, -Inf, and NaN converted to NA.

Examples

Run this code
# NOT RUN {
# a vector
x <- c(1, 2, NA, 3, NaN, 4, NA, 5, Inf, -Inf, 6, 7)
replace_nan_inf(x)

# a dataframe
df <- data.frame(
  x = c(1, NA, 5, Inf, 2, NA),
  y = c(3, NaN, 4, -Inf, 6, 7),
  stringsAsFactors = FALSE
)
replace_nan_inf(df)
# }

Run the code above in your browser using DataLab