rationalize: Only allow rational values in numeric vectors 'rationalize'...

View source: R/hablar.R

rationalizeR Documentation

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, ...)

## Default S3 method:
rationalize(.x, ...)

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

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

Arguments

.x

vector or data.frame

...

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

Details

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

Value

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

For data.frame: a tbl data frame.

NULL

NULL

NULL

See Also

s, rationalize, vignette("s"), vignette("hablar")

Examples

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)


hablar documentation built on March 31, 2023, 11:54 p.m.