Learn R Programming

hablar (version 0.1.0)

rationalize: Only allow rational values in numeric vectors

rationalize transforms all numeric elements to be rational values or NA, thus removes all NaN,Inf and replaces them with NA.

Description

Only allow rational values in numeric vectors

rationalize transforms all numeric elements to be rational values or NA, thus removes all NaN,Inf and replaces them with NA.

Usage

rationalize(.x, ...)

# S3 method for default rationalize(.x, ...)

# S3 method for numeric rationalize(.x, ...)

# S3 method for data.frame rationalize(.x, ...)

Arguments

.x

vector or data.frame

...

columns to be evaluated. Only applicable if .x is a data frame.

Value

For vectors: same data type/class as .x.

For data.frame: a tbl data frame.

NULL

NULL

NULL

Details

#' If a non-numeric vector is passed, it is unchanged. If a data.frame is passed, it evaluates all columns separately.

See Also

s, rationalize

Examples

Run this code
# NOT RUN {
x <- c(3, -Inf, 6.56, 9.3, NaN, 5, -Inf)
rationalize(x)

df <- data.frame(num_col = c(Inf, 3, NaN), 
                 chr_col = c("a", "b", "c"), 
                 stringsAsFactors = FALSE)
df
rationalize(df)

# }

Run the code above in your browser using DataLab